



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to various problems related to linked lists. It includes functions to delete the first node, add a node to the end, copy a list, add a node at a specific position, remove the first element, count duplicate items, count nodes in a circular list, and reverse a list using a stack. The document also includes code snippets for each function.
Typology: Lab Reports
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Assume the following node structure: struct node { int data; struct node *next; }
Second = copy(First); Write the following function: struct node *copy(struct node *list )
Solution: void extend(struct node *p, struct node * q) { struct node t; / t is used to traverse the lists / if ( __ q == NULL ____________ ) / if standard linked list is empty / return; t = p; / Assume p cannot be NULL / while ( t->next != p ) /traverse the circular list / t = t ->next ; t->next = q _________; / append the standard list / while ( t->next != NULL ) / traverse the std. list */ t = t->next ; t->next = _ p ;
struct node* front = (struct node) (malloc(sizeof(struct node))); struct node back = (struct node*) (malloc(sizeof(struct node))); stackA = NULL; pCur =A; while(pCur!=NULL) { dd = pCur->data; push(&stackA, dd); pCur=pCur->next; } front=NULL; back=NULL; //Now pop the nodes from stackA and append to a new list B do { dd = pop(&stackA); enqueue(&front,dd,&back); } while (stackA !=NULL);