Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

- Write a function called CreateList() that creates a linked list without an ass

ID: 3583894 • Letter: #

Question

- Write a function called CreateList() that creates a linked list without an assumption related to the length of the linked list. When the user enters -1 as a value, the linked list should finish.

- Write a C function called MaxValue() that takes a linked list and returns the maximum value in this linked list. Assume that the list does not include repeated values.

- Write a function called SumList() that takes a linked list and returns the total of the values in the given linked list.

- Implement a recursive C function RecursivePrintList() that traverses a linked list and prints out the values.

-. Write a recursive function called recursiveSumList() that takes a linked list and returns the total of the values in the given linked list.

- Implement a C function CopyList() that takes a linked list and makes a copy of it. Let the function return the pointer to the first element of the list as a result.

- Write a function called inner_product() that takes two linked list as an input. The function should return their inner product. If two linked lists are not the same length, you can continue to inner product till the end of the long linked list and assume that the remaining values of shorter linked list are 0. You can find an example below which shows how the inner product of two array is calculated.

int inner_product(int *a, int *b) a and b both are linked list. a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+…+a[n-1]b[n-1]

Explanation / Answer

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
   typedef struct nodetype
   {
       int info;
       nodetype *next ;
   } node;
   int item,ch,max=0,sum=0,mul=0;
   node *ptr,*head,*temp,*head1;
   void CreateList(node **head, int);
int MaxValue(node *head);
   int SumList(node *head);
   void traverse(node *head);
   int MaxValueR(node *head);
   int SumListR(node *head);
   void traverseR(node *head);
   node *copy(node *head);
int main()
   {  
       while(1)
       {
       printf("PRESS (1) FOR CREATING LINKLIST ");
       printf("PRESS (2) FOR TRAVERSE LIST ");
       printf("PRESS (3) FOR FINDING MAXIMUM IN LINKLIST ");
       printf("PRESS (4) FOR FINDING SUM OF LINKLIST ");
       printf("PRESS (5) FOR RECURSIVE TRAVERSE OF LIST ");
       printf("PRESS (6) FOR FINDING MAXIMUM IN LINKLIST USING RECURSIVE FUNCTION ");
       printf("PRESS (7) FOR FINDING SUM OF LINKLIST USING RECURSIVE FUNCTION ");
       printf("PRESS (8) FOR CREATE COPY ");
       printf("PRESS (9) FOR EXIT FROM MENUE ");
       printf("ENTER YOUR CHOICE ");
       scanf("%d",&ch);
           switch(ch)
           {
               case 1:
               printf("ENTER THE VALUE ") ;
               scanf("%d",&item);
               CreateList(&head,item);
               case 2:
               traverse(head);
               break;
               case 3:
               max=MaxValue(head);
               printf("The Maximum Value Of The LinkedList is: %d",max);
               printf(" ");
               break;
               case 4:
               sum=SumList(head);
               printf("The SUM Of The LinkedList is: %d",sum);
               printf(" ");
               break;
               case 5:
               traverseR(head);
               break;
               case 6:
               max=MaxValueR(head);
               printf("The Maximum Value Of The LinkedList Using Recursive Function is: %d",max);
               printf(" ");
               break;
               case 7:
               sum=SumListR(head);
               printf("The SUM Of The LinkedList Using Recursive Function is: %d",sum);
               printf(" ");
               break;
               case 8:
               temp=copy(head);
               case 9:
               exit(1);
           }
       }
   //   getch();
   return 0;
   }
               void CreateList(node **head,int item)
               {
                   temp= ( node * ) malloc (sizeof( node ));
                   temp->info= item;
                   temp->next= NULL;
                   temp->next= *head;
                   *head= temp;
               }
               void traverse(node *head)
               {
                   ptr = head;
                   while(ptr!=NULL)
                   {
                       printf("%d ",ptr->info);
                       ptr=ptr->next;
                   }
                   printf(" ");
               }
               int MaxValue(node *head)
               {
                   ptr = head;
                   int m=ptr->info;
                       while(ptr!=NULL)
                       {
                           if(m<ptr->info)
                           m=ptr->info;
                           ptr=ptr->next;
                       }
                   return m;
               }
               int SumList(node *head)
               {
                   ptr = head;
                   int s=0;
                       while(ptr!=NULL)
                       {
                           s = s+ptr->info;
                           ptr=ptr->next;
                       }
                   return s;
               }
   void traverseR(node *head)
               {
                   ptr = head;
                   if(ptr==NULL)
                   {
                       return;
                   }
                   else
                   {
                       printf("%d ",ptr->info);
                       traverseR(ptr->next);
                   }
               }
               int MaxValueR(node *head)
               {
                   ptr = head;
                   int m=ptr->info;
                   int n;
                       if(ptr->next=NULL)
                       {
                           return m;
                       }
                       else
                       {
                           n=MaxValueR(ptr->next);
                       }
                       if(m>n)
                       {
                           return m;
                       }
                       else
                       {
                           return n;
                       }
               }
               int SumListR(node *head)
               {
                   ptr = head;
                   int s=0;
                   if(ptr==NULL)
                       {
                           return 0;
                       }
                       else
                       {
                           s=s+SumListR(ptr->next);
                       }
                   return s;
               }
               node *copy(node *head)
               {
               temp= ( node * ) malloc (sizeof( node ));
               ptr=head;
               while(ptr!=head)
               {
                   temp->info=ptr->info;
                   temp->next=temp;
                   ptr=ptr->next;
               }
                   return temp;
               }

dear friend the question is too long i will try to solve it within timelimit but it exeeded so i will post remainin part within one or two days..

Thank You..