






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
The process of performing operations on a linked list, including inserting, deleting, and traversing nodes. It provides a typical declaration of a node and explains how to insert a node at the beginning, end, or in between a linked list. The document also includes sample code in C++ for a menu-driven program that allows users to perform various operations on a linked list.
Typology: Lab Reports
1 / 11
This page cannot be seen from the preview
Don't miss anything!







LAB TASKS
#include
cout<<"\n\t\t>>>>>>>> Menu of Linked list <<<<<<<<"; cout<<"\n"; cout<<"\n------------------------------------------------------------------"; cout<<"\n\tENTER 1: Insertion node at the beginning"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 2: Insert node at given position"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 3: Insert node at last"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 4: Displaying linked list"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 5: Total Element in linked list"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 6: Search Element in linked list"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 7: Delete a Particular Node"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\tENTER 8: To Exit"; cout<<"\n\t\t-----------------------------------"; cout<<"\n\n\tPlease Enter Your Choice: "; cin>>ch; switch(ch) { case 1: system("cls"); sl.insert_begin();Sleep(1000);system("cls"); break; case 2: system("cls"); sl.insert_pos();Sleep(1000);system("cls"); break; case 3: system("cls"); sl.insert_last();Sleep(1000);system("cls"); break; case 4: system("cls"); sl.display();Sleep(3000);system("cls"); break; case 5: system("cls"); sl.count();Sleep(3000);system("cls"); break; case 6: system("cls"); sl.search();Sleep(3000);system("cls"); break; case 7: system("cls"); sl.delete_pos();Sleep(1000);system("cls"); break; case 8: cout<<"\n\tExiting..........."<<endl; exit(1); break; default: cout<<"\n\n\t\t\aINVALID CHOICE ?? \a\n";Sleep(1000);system("cls");break; }
start = temp; start->next = NULL; } else { ptr = start; start = temp; start->next = ptr; } } else if (pos > 1 && pos <= counter) { s = start; for (i = 1; i < pos; i++) { ptr = s; s = s->next; } ptr->next = temp; temp->next = s; } else { cout<<"\n\n\n\t\tPositon out of range......."<<endl; } } void single_llist::insert_last() { int value; cout<<"\n\n\n\t\tEnter the value to be inserted: "; cin>>value; struct node *temp, *s; temp = create_node(value); s = start; while (s->next != NULL) { s = s->next; } temp->next = NULL; s->next = temp; cout<<"\n\n\t\tElement Inserted at last Sucessfully...."<<endl; } void single_llist::display() { struct node *temp; if (start == NULL) { cout<<"\n\n\n\t\tThe List is Empty......!!!"<<endl; return; } temp = start; cout<<"\n\n\n\t\tElements of list are: "; while (temp != NULL) { cout<<temp->info<<"->"; temp = temp->next; } cout<<"NULL"<<endl;
void single_llist::search() { int value, pos = 0; bool flag = false; if (start == NULL) { cout<<"\n\n\n\t\tList is empty"<<endl; return; } cout<<"\n\n\n\t\tEnter the value to be searched: "; cin>>value; struct node *s; s = start; while (s != NULL) { pos++; if (s->info == value) { flag = true; cout<<"\n\n\n\t\tElement "<<value<<" is found at position "<<pos<<endl; } s = s->next; } if (!flag) cout<<"\n\n\n\t\tElement "<<value<<" not found in the list"<<endl; } void single_llist::delete_pos() { int pos, i, counter = 0; if (start == NULL) { cout<<"\n\n\n\t\tList is empty"<<endl; return; } cout<<"\n\n\n\t\tEnter the position of value to be deleted: "; cin>>pos; struct node *s, *ptr; s = start; if (pos == 1) { start = s->next; } else { while (s != NULL) { s = s->next; counter++; } if (pos > 0 && pos <= counter) { s = start; for (i = 1;i < pos;i++) { ptr = s; s = s->next; }