Ask Question
4 October, 03:52

Write a function which multiplies the values in odd position values by 10. Odd positions in this case refers to the first value in the list, the third value, the fifth value etc

+1
Answers (1)
  1. 4 October, 04:06
    0
    Using linkedlist on C++, we have the program below.

    Explanation:

    #include

    #include

    using namespace std;

    //structure of linked list

    struct linkedList

    {

    int data;

    struct linkedList * next;

    };

    //print linked list

    void printList (struct linkedList * head)

    {

    linkedList * t=head;

    while (t!=NULL)

    {

    cout
    if (t->next!=NULL)

    cout< ";

    t=t->next;

    }

    }

    //insert newnode at head of linked List

    struct linkedList * insert (struct linkedList * head, int data)

    {

    linkedList * newnode=new linkedList;

    newnode->data=data;

    newnode->next=NULL;

    if (head==NULL)

    head=newnode;

    else

    {

    struct linkedList * temp=head;

    while (temp->next!=NULL)

    temp=temp->next;

    temp->next=newnode;

    }

    return head;

    }

    void multiplyOddPosition (struct linkedList * head)

    {

    struct linkedList * temp=head;

    while (temp!=NULL)

    {

    temp->data = temp->data*10; / /multiply values at odd position by 10

    temp = temp->next;

    //skip odd position values

    if (temp! = NULL)

    temp = temp->next;

    }

    }

    int main ()

    {

    int n, data;

    linkedList * head=NULL;

    / / create linked list

    head=insert (head, 20);

    head=insert (head, 5);

    head=insert (head, 11);

    head=insert (head, 17);

    head=insert (head, 23);

    head=insert (head, 12);

    head=insert (head, 4);

    head=insert (head, 21);

    cout<<"/nLinked List : ";

    printList (head); / /print list

    multiplyOddPosition (head);

    cout<<"/nLinked List After Multiply by 10 at odd position : ";

    printList (head); / /print list

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a function which multiplies the values in odd position values by 10. Odd positions in this case refers to the first value in the ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers