






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







void double_llist::add_begin(int value) { if (start == NULL) { cout<<"\n\n\t\tFirst Create the list."<<endl; return; } struct node *temp; temp = new(struct node); temp->prev = NULL; temp->info = value; temp->next = start; start->prev = temp; start = temp; cout<<"\n\n\t\tElement Inserted Sucessfully...!!!"<<endl; }
void double_llist::add_after(int value, int pos) { if (start == NULL) { cout<<"\n\n\t\tFirst Create the list"<<endl; return; } struct node *tmp, *q; int i; q = start; for (i = 0;i < pos - 1;i++) { q = q->next; if (q == NULL) { cout<<"\n\n\t\tThere are less than "; cout<<pos<<" elements."<<endl; return; } } tmp = new(struct node); tmp->info = value; if (q->next == NULL) { q->next = tmp; tmp->next = NULL; tmp->prev = q; } else { tmp->next = q->next; tmp->next->prev = tmp; q->next = tmp; tmp->prev = q; } cout<<"\n\n\t\tElement Inserted Sucessfully...!!!"<<endl; }
#include<stdio.h> #include<windows.h> #include
case 2: system("cls"); cout<<"\n\n\t\tEnter the element: "; cin>>element; cout<<"\n\n\n\t\tEnter the postion: "; cin>>position; dl.add_after(element, position); Sleep(500);system("cls"); break; case 3: system("cls"); cout<<"\n\n\t\t"; dl.display_dlist(); Sleep(5000);system("cls"); break; case 4: system("cls"); dl.count(); Sleep(1000);system("cls");break; case 5: system("cls"); if (start == NULL) { cout<<"\n\n\t\tList is empty, Nothing to reverse.....!!!"<<endl; Sleep(1000);system("cls"); break; } dl.reverse(); dl.display_dlist(); Sleep(5000);system("cls"); break; case 6: system("cls"); if (start == NULL) { cout<<"\n\n\t\tList empty, Nothing to delete....!!!"<<endl; Sleep(1000);system("cls"); break; } cout<<"\n\n\t\tEnter the element for deletion: "; cin>>element; dl.delete_element(element); Sleep(500);cout<<"\n\n\t\tNew ";dl.display_dlist(); Sleep(5000);system("cls"); break; case 7: cout<<"\n\tExiting..........."<<endl; exit(1); default: cout<<"\n\n\t\t\aINVALID CHOICE ?? \a\n";Sleep(1000);system("cls");break; } } return 0; } void double_llist::create_list(int value) { struct node *s, *temp; temp = new(struct node); temp->info = value; temp->next = NULL; if (start == NULL) { temp->prev = NULL; start = temp;
struct node *tmp, *q; if (start->info == value) { tmp = start; start = start->next; start->prev = NULL; cout<<"\n\n\t\tElement Deleted Sucessfully...!!!"<<endl; free(tmp); return; } q = start; while (q->next->next != NULL) { if (q->next->info == value) { tmp = q->next; q->next = tmp->next; tmp->next->prev = q; cout<<"\n\n\t\tElement Deleted Sucessfully...!!!"<<endl; free(tmp); return; } q = q->next; } if (q->next->info == value) { tmp = q->next; free(tmp); q->next = NULL; cout<<"\n\n\t\tElement Deleted Sucessfully...!!!"<<endl; return; } cout<<"\n\n\t\tElement "<<value<<" not found"<<endl; } void double_llist::display_dlist() { struct node *q; if (start == NULL) { cout<<"\n\n\t\tList empty, Nothing to display...!!!"<<endl; return; } q = start; cout<<"Doubly Link List is : "; while (q != NULL) { cout<<q->info<<" <-> "; q = q->next; } cout<<"NULL"<<endl; } void double_llist::count() { struct node *q = start; int cnt = 0; while (q != NULL) { q = q->next; cnt++; } cout<<"\n\n\t\tNumber of elements are: "<<cnt<<endl; } void double_llist::reverse() {
struct node *p1, *p2; p1 = start; p2 = p1->next; p1->next = NULL; p1->prev = p2; while (p2 != NULL) { p2->prev = p2->next; p2->next = p1; p1 = p2; p2 = p2->prev; } start = p1; cout<<"\n\n\t\tList Reversed Sucessfully...!!!"<<endl; Sleep(500); cout<<"\n\n\t\tNew "; }