Linked List complete Project

Linked List complete Project

 Complete Linked list program that includes insertion and deletion functions for both types of linked list and circular linked list as well .You can copy this code and can also download it . Scroll down and click download option . #include<iostream> using namespace std; struct node { int data; node *link; }; struct node_c { int data; node_c *lnk; }; struct node_d { int data; node_d *next, *pre; }; class link_list { static int l, d, n; node *start, *temp, *cur; node_c *st, *tm, *cu; node_d *s, *t, *c; public: link_list() { start = NULL; s = NULL; st = NULL; } void create_double(int val) { d++; if (s == NULL) { t = new node_d; t->data = val; t->pre = NULL; t->next = NULL; s = t; } else { node_d *p; p = t; c = s; while (c->next != NULL) c = c->next; t = new node_d; t->data = val; t->pre = p; c->next = t; t->next = NULL; } } void modify_d(int val, int p) { node_d *prev; prev=t=c=s; if (p == 1) { t = new node_d; t->data = val; t->pre = NULL; t->next = s; s->pre = t; s = t; } else if (p == d) { t = new node_d; t->data = val; t->pre = c; t->next = c->next; c->next = t; c = c->next; c->pre = t; } else { for (int i = 1;i < p – 1;i++) { c = c->next; } prev = c->next; t = new node_d; t->data = val; t->pre = c; t->next = prev; c->next = t; prev->pre=t; c->pre = t; } d++; } void del_d(int val) { c = t = s; if (c->data == val && c == s) { s = s->next; s->pre = NULL; cout << “\n\t\tNode has Been deleted \n”; delete t; } else { while (c->next != NULL) { if (c->data == val) { t->next = c->next; t = t->next; t->pre = c->pre; delete c; cout << “\n\n\t\tNode has Been Deleted \n”; goto out; //break; } t = c; c = c->next; } if (c->data == val) { t->next = NULL; delete c; cout << “\n\n\t\tNode Has Been Deleted\n”; goto out; } cout << “\n\t\tNode Not Found\n”; } out: system(“pause”); } void del_p(int p) { c = t = s; if (p <= d) { if (p == 1) { s = s->next; s->pre = NULL; delete t; goto out; } else if (p == d) { for (int i = 1;i < p;i++) { t = c; c = c->next; } t->next = NULL; delete c; } else { for (int i = 1;i < p;i++) { t = c; c = c->next; } t->next = c->next; t = c->next; t->pre = c->pre; delete c; out: cout << “\n\t\tNode has been deleted\n”; } } else { cout << “\n\t\tInvalid Position\n”; } } void print_double() { c = s; int count = 0; while (c->next != NULL) { count = count + 1; cout << “\n\t\tNode ” << count << ” has Data ” << c->data << endl; c = c->next; } count = count + 1; cout << “\n\t\tNode ” << count << ” Has Data ” << c->data << endl; } void create_simple(int val) { l++; if (start == NULL) { temp = new node; temp->data = val; temp->link = NULL; start = temp; } else { cur = start; while (cur->link != NULL) cur = cur->link; temp = new node; temp->data = val; temp->link = NULL; cur->link = temp; } } void modify_simple(int p, int val) { cur = start; l++; if (p == 1) { temp = new node; temp->data = val; temp->link = start; start = temp; } else { for (int i = 1;i < p – 1;i++) { cur = cur->link; } temp = new node; temp->data = val; temp->link = cur->link; cur->link = temp; } } void del_simple(int val) { temp = cur = start; if (cur->data == val && cur == start) { start = start->link; delete temp; cout << “\n\n\t\tNode has been Deleted \n”; } else { while (cur->link != NULL) { if (cur->data == val) { temp->link = cur->link; delete cur; cout << “\n\t\tNode Has Been Deleted\n”; break; } temp = cur; cur = cur->link; } if (cur->data == val) { temp->link = cur->link; delete cur; cout << “\n\n\t\tNode has been Deleted\n”; } } } void del_loc(int p) { temp = cur = start; if (p <= l) { if (p == 1) { start = start->link; delete temp; } else { for (int i = 1;i < p;i++) { temp = cur; cur = cur->link; } temp->link = cur->link; delete cur; } } else cout << “\n\n\t\tInvalid\n”; } void print_simple() { cur = start; int c = 0; while (cur->link != NULL) { c = c + 1; cout << “\n\t\tNode ” << c << ” has ” << cur->data << endl; cur = cur->link; } c = c + 1; cout << “\n\t\tNode ” << c << ” Has ” << cur->data << endl; } void create_Circular(int val) { if (st == NULL) { tm = new node_c; tm->data = val; tm->lnk = tm; st = tm; n++; } else { cu = st; while (cu->lnk != st) cu = cu->lnk; tm = new node_c; tm->data = val; tm->lnk = st; cu->lnk = tm; n++; } } void modify_circular(int p, int val) { cu = st; if (p == 1) { tm = new node_c; tm->data = val; tm->lnk = st; while (cu->lnk != st) cu = cu->lnk; cu->lnk = tm; st = tm; } else { for (int i = 1;i < p – 1;i++) cu = cu->lnk; tm = new node_c; tm->data = val; tm->lnk = cu->lnk; cu->lnk = tm; } n++; } void del_Circular(int val) { cu = tm = st; if (cu->data == val && cu == st) { while (cu->lnk != st) cu = cu->lnk; st = st->lnk; cu->lnk = st; delete tm; cout << “\n\t\tNode has been Deleted\n”; } else { while (cu->lnk != st) { if (cu->data == val) { tm->lnk = cu->lnk; delete cu; cout << “\n\t\tNode Has Been Deleted\n”; break; } tm = cu; cu = cu->lnk; } if (cu->data == val) { tm->lnk = cu->lnk; cout << “\n\t\tNode has been deleted\n”; delete cu; } } } void del_l(int p) { cu = tm = st; if (p <= n) { if (p == 1) { while (cu->lnk != st) cu = cu->lnk; st = st->lnk; cu->lnk = st; delete tm; cout << “\n\n\t\tNode has Been Deleted\n”; } else { for (int i = 1;i < p;i++) { tm = cu; cu = cu->lnk; } tm->lnk = cu->lnk; delete cu; cout << “\n\t\tNode has Been Deleted\n”; } } else cout << “\n\n\t\tInvalid position\n”; } void print_circular() { int c = 0; cu = st; while (cu->lnk != st) { c = c + 1; cout << “\n\t\tNode ” << c << ” has ” << cu->data << endl; cu = cu->lnk; } c = c + 1; cout << “\n\t\tNode ” << c << ” has ” << cu->data << endl; } void count() { cout << “\n\n\t\tCircular LIned List Nodes ” << n; cout << “\n\n\t\tSingle LInked List Nodes ” << l; cout << “\n\n\t\tDouble Linked List Nodes ” << d; system(“pause”); } }; int link_list::l = 0; int link_list::d = 0; int link_list::n = 0; int main() { link_list obj; int val, p, choice; while (1) { system(“cls”); start: cout << “\n\n\t\t\tChap # 07\n\n”; cout << “\n\t\t1:Single Linked List\n”; cout << “\n\t\t2:Circular Linked List\n”; cout << “\n\t\t3:Double Linked List\n”; cout << “\n\t\t4:EXit\n”; cout << “\n\t\tEnter your Choice “; cin >> choice; switch (choice) { case 1: while (1) { single: system(“cls”); cout << “\n\n\t\t\tSingle Linked List Management Area\n\n\n”; cout << “\t\t1:Create New Node \n”; cout << “\n\t\t2:Display All Data in Node\n”; cout << “\n\t\t3:Modifying Simple Linked List\n”; cout << “\n\t\t4:Deleting the Node \n”; cout << “\n\t\t5:Exit\n”; cout << “\n\t\tEnter your choice “; cin >> choice; switch (choice) { case 1: system(“cls”); cout << “\n\n\t\t\tCreating a New Node\n\n”; cout << “\t\tEnter Data that you want to store in Node “; cin >> val; obj.create_simple(val); cout << “\n\t\tNode Has Been Created \n”; system(“pause”); break; case 2: system(“cls”); cout << “\n\t\t\tData In Single Linked List\n\n”; obj.print_simple(); system(“pause”); break; case 3: system(“cls”); cout << “\n\n\t\t\tModifying the Single Linked List\n\n”; cout << “\n\t\tEnter the value and position “; cin >> val >> p; obj.modify_simple(p, val); cout << “\n\t\tSinge Linked Has Been modified \n”; system(“pause”); break; case 4: system(“cls”); cout << “\n\n\t\t\tDeleting the Existing Node\n\n”; cout << “\n\t\t1:Deleting Node by Value \n”; cout << “\n\t\t2:Deleting Node by Position\n”; cout << “\n\t\t3:Go to Single Linked Management Area\n”; cout << “\n\t\tEnter your choice “; cin >> choice; switch (choice) { case 1: system(“cls”); cout << “\n\n\t\t\tDeleting Node By Value\n\n”; cout << “\n\n\t\tEnter the value “; cin >> val; obj.del_simple(val); system(“pause”); break; case 2: system(“cls”); cout << “\n\n\t\t\tDeleting Node By Value\n\n”; cout << “\n\t\tEnnter the Position “; cin >> p; obj.del_loc(p); system(“pause”); break; case 3: system(“cls”); goto single; } break; case 5: system(“cls”); goto start; } } break; case 2: while (1) { circular: system(“cls”); cout << “\n\n\t\t\t Circular Linked List Management Area\n\n\n”; cout << “\t\t1:Create New Node \n”; cout << “\n\t\t2:Display All Data in Node\n”; cout << “\n\t\t3:Modifying the Circular Linked List\n”; cout << “\n\t\t4:Deleting the Node\n”; cout << “\n\t\t5:Exit\n”; cout << “\n\t\tEnter your choice “; cin >> choice; switch (choice) { case 1: system(“cls”); cout << “\n\n\t\t\tCreating a New Node\n\n”; cout << “\t\tEnter Data that you want to store in Node “; cin >> val; obj.create_Circular(val); cout << “\n\t\tNode Has Been Created \n”; system(“pause”); break; case 2: system(“cls”); cout << “\n\t\t\tData In circular Linked List\n\n”; obj.print_circular(); system(“pause”); break; case 3: system(“cls”); cout << “\n\n\t\t\tModifying Circular Linked list\n\n”; cout << “\n\t\tEnter the value “; cin >> val; cout << “\n\t\tEnter the Position where you want to create node “; cin >> p; obj.modify_circular(p, val); cout << “\n\t\tCircular Linked Has Been Modified \n”;; system(“pause”); break; case 4: system(“cls”); cout << “\n\n\t\t\tDeleting the Node \n\n”; cout << “\n\t\t1: Deleting the node by value \n”; cout << “\n\t\t2: Deleting the node by Position\n”; cout << “\n\t\t3: Go to Circular Linked Management Area\n”; cout << “\n\t\tEnter your choice “; cin >> choice; switch (choice) { case 1: system(“cls”); cout << “\n\n\t\t\tDeleting the Node by value\n”; cout << “\n\t\tEnter the value “; cin >> val; obj.del_Circular(val); system(“pause”); break; case 2: system(“cls”); cout << “\n\n\t\t\tDeleting the Node by Position\n”; cout << “\n\t\tEnter the Position “; cin >> p; obj.del_l(p); system(“pause”); break; case 3: system(“cls”); goto circular; } break; case 5: system(“cls”); goto start; } } break; case 3: while (1) { d: system(“cls”); cout << “\n\n\t\t\t Double Linked List Management Area\n\n\n”; cout << “\t\t1:Create New Node \n”; cout << “\n\t\t2:Display All Data in Node\n”; cout << “\n\t\t3:Modifying the Double Linked List\n”; cout << “\n\t\t4:Deleting the Node\n”; cout << “\n\t\t5:Exit\n”; cout << “\n\t\tEnter your choice “; cin >> choice; switch (choice) { case 1: system(“cls”); cout << “\n\n\t\t\tCreating a New Node\n\n”; cout << “\t\tEnter Data that you want to store in Node “; cin >> val; obj.create_double(val); cout << “\n\t\tNode Has Been Created \n”; system(“pause”); break; case 2: system(“cls”); cout << “\n\t\t\tData In Dougle Linked List\n\n”; obj.print_double(); system(“pause”); break; case 3: system(“cls”); cout << “\n\n\t\t\tModifying the Double Linked List\n\n”; cout << “\n\t\tEnter the Value “; cin >> val; cout << “\n\t\tEnter the Position “; cin >> p; obj.modify_d(val, p); cout << “\n\t\tDouble Linked List Has Been Modified\n”; system(“pause”); break; case 4: system(“cls”); cout << “\n\n\t\t\tDeleting the Node\n\n”; cout << “\n\t\t1:Deleting the Node By Value \n”; cout << “\n\t\t2:Deleting the Node By Position\n”; cout << “\n\t\t3:Go To Double Linked Management Area\n”; cout << “\n\t\tEnter your choice “; cin >> choice; switch (choice) { case 1: system(“cls”); cout << “\n\n\t\t\tDeleting the Node by Value \n\n”; cout << “\n\t\tEnter the Value “; cin >> val; obj.del_d(val); system(“pause”); break; case 2: system(“cls”); cout << “\n\n\t\t\tDeleting the node by Position\n\n”; cout << “\n\t\tEnter the Position “; cin >> p; obj.del_p(p); system(“pause”); break; case 3: system(“cls”); goto d; } break; case 5: system(“cls”); goto start; system(“pause”); } } break; case 4: system(“cls”); cout << “\n\n\t\tTotal Number of nodes\n\n”; obj.count(); goto out; } } out: system(“pause”); } Linked List Project Download  

One Reply to “Linked List complete Project”

  1. Heya i’m for the first time here. I found this board and I to find It truly useful & it helped me out much. I’m hoping to provide one thing back and aid others such as you helped me.

Leave a Reply

Your email address will not be published. Required fields are marked *