Dsa Proj

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Dsa Proj as PDF for free.

More details

  • Words: 4,619
  • Pages: 71
DATA STRUCTURE

(INTO C++)

DSA PROJECT ALGOS IMPLEMENTATION INTO C++

1

ALGOS IMPLEMENTATION (INTO C++)

SUBMITTED BY:

ABID QADOOS M.SC-1 EVENING

SUBMITTED

TO:

SIR NAUMAN QADEER SB

DSA PROJECT ALGOS IMPLEMENTATION INTO C++

2

IN THE NAME OF ALMIGHTY ALLAH THE MOST BENEFICENT, THE MOST MERCIFUL

DSA PROJECT ALGOS IMPLEMENTATION INTO C++

3

DEDICATED TO

MY LOVING PARENTS

WORTHY TEACHER NAUMAN SB. & COLLEAGUES (ARSHAD, ADNAN, WAHEED & SHAFIQ)

DSA PROJECT ALGOS IMPLEMENTATION INTO C++

4

Table of Con tents

TABLE OF CONTENTS.......................................................................................................................................5

PROGRAM

CODE

#include #include #include int a[100]; int n,i,j,k,item,stsize,qsize; int lb=0; int choice; int st[10];int cq[10]; int top=-1;int q[10];int r=-1;int f=-1; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

5

void heading(); void welcome(); void mmenu(); void array(); void traverse(); void insertion(); void deletion(); void search(); void sort(); void bubblesort(); void insertsort(); void selectsort(); void shellsort(); void merging(); void stack(); void push(); void pop(); void queue(); void qinsert(); void qdelete(); void cqinsertion(); void cqdelete(); void linklist(); void slinklist(); void sll_traverse(); void sll_insertion(); void linkaf(); void linkal(); void linkbg(); void linkag(); void sll_deletion(); void linkaf_d(); void linkal_d(); void linkag_d(); void dlinklist(); void dll_traverse(); void dll_insertion(); void dll_ins_af(); void dll_ins_al(); void dll_ins_bg(); void dll_ins_ag(); void dll_deletion(); void dll_del_af(); void dll_del_al(); void dll_del_ag(); struct link2 { int info; link2 *next; }; struct dlink_list { int info; dlink_list *next; dlink_list *previous; };

1. int main() { clrscr(); welcome(); mmenu(); getch(); DSA PROJECT ALGOS IMPLEMENTATION INTO C++

6

return 0; }

2. void heading() { clrscr(); cout<<"*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*"; cout<<"\n\n\n\t\t\tDATA STRUCTURE & ALGORITHMS"; cout<<"\n\n\t\t\tPROJECT OF ALGOS IMPLEMENTATION INTO C++"; cout<<"\n\n\n*****************************************************"; }

3. void welcome() { clrscr(); heading(); for (int i=1;i<10;i++) { cout<<"\n\t\t\t\t*!!*"; } cout<<"\n\n

\n\n

Submitted By:- ABID QADOOS AWAN

";

cout<<"\n\@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n"; cout<<"\n\n\n\n\n

Submitted To:- NAUMAN QADEER SB.";

for (int j=1;j<10;j++) { cout<<"\n\n\t\t\t\t*!!*"; } cout<<"\n********************************************************"; getch(); clrscr(); }

4. void mmenu() { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

7

clrscr(); while (choice!=-1) { clrscr(); heading(); cout<<"*\n*\n*\n Enter your choice to choose a data structure type"; cout<<"*\n*\n\t\t\t 1 = ARRAY\n"; cout<<"*\n*\n\t\t\t 2 = STACK\n"; cout<<"*\n*\n\t\t\t 3 = QUEUE\n\n"; cout<<"*\n*\n\t\t\t 4 = LINK LIST \n\n"; cout<<"*\n****************************************************"; cout<<"\n\n PRESS '-1' FOR EXIT\n\n"; cout<<"\n\t Enter Your Choice\t=\t"; cin>>choice; switch(choice) { case 1: array(); break; case 2: stack(); break; case 3: queue(); break; case 4: linklist(); break; default: cout<<" Press Correct Option"; break; } } clrscr(); DSA PROJECT ALGOS IMPLEMENTATION INTO C++

8

heading(); cout<<"\n\n\t\t ALLAH HAFIZ"; getch(); }

5. void array() { clrscr(); heading(); cout<<"\n\n\t\tEnter the no of elements in Array b/w (1-100)\t=\t"; cin>>n; while (choice!=-1) clrscr(); heading(); cout<<"\n\n\n Enter your choice to choose a operation on array"; cout<<"\n\n\t\t\t TRAVERSING>>.>.>.>.>.>.>>\t1\n"; cout<<"\n\n\t\t\t INSERTION>>.>.>.>.>.>.>.>\t2\n"; cout<<"\n\n\t\t\t DELETION>>.>.>.>.>.>.>.>>\t3\n"; cout<<"\n\n\t\t\t SEARCHING>>.>.>.>.>.>..>>\t4\n"; cout<<"\n\n\t\t\t MERGING>>.>.>.>.>.>.>.>.>\t5\n"; cout<<"\n\n\t\t\t SORTING>>.>.>.>.>.>.>.>.>\t6\n"; cout<<"\n\n\t\t\t EXIT>>.>.>.>.>.>.>.>.>.>>\n\n"; cout<<"\n\n\t\t ENTER YOUR CHOICE HERE\t"; cin>>choice; switch(choice) { case 1: clrscr(); traverse(); break; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

9

case 2: clrscr(); insertion(); break; case 3: clrscr(); deletion(); break; case 4: search(); break; case 5: merging(); break; case 6: sort(); break; default: cout<<" Press Correct Option"; mmenu(); } } getch(); }

6. void traverse() { clrscr(); heading(); cout<<"\n\n

TRAVERSING OF ARRAY

";

cout<<"\n***********************************************************"; if(a[i]
10

array(); } cout<<"\n\n\n******************************************************\n"; for (j=0;j
7. void insertion() { heading(); cout<<"\n\n\t\t\t\tINSERTION IN ARRAY"; cout<<"\n**********************************************************"; cout<<"\nEnter the position where insertion take place\t=\t"; cin rel="nofollow">>k; cout<<"\nEnter the item which may be inserted at given position\t=\t"; cin>>item; if ((n>=20)||((k<0)||(k>(n+1)))) { cout<<"\nInsertion can not take place"; } for(i=(n-1);i>=k;i--) { a[i+1]=a[i]; } a[k]=item; n=n+1; cout<<"\n\n\n No of elements in array"<
11

cout<<"\n"<
8. void deletion() { clrscr(); heading(); cout<<"\n\t\t\t DELETION IN ARRAY"; cout<<"\n***************************************************************\n"; cout<<"\n\n Enter the position of element u want to delete\t=\t"; cin rel="nofollow">>k; if ((k(n-1))) { cout<<"deletion can not possible. Array is empty"; getch(); array(); } else { item=a[k]; cout<<"\n\n deleted value is\t=\t"<
9. void search() { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

12

int choice; int item,i,beg,midpos,end; int count=0; int j; clrscr(); heading(); cout<<"\n\nEnter Your Choice for searching type\t"; cout<<"\n\n\n\t\tLinear Search Single>>.>.>.>.>.>.>>\t1\n"; cout<<"\n\n\n\t\tLinear Search Multiple>>.>.>.>.>.>.>>\t2\n"; cout<<"\n\n\n\t\tBinary Search Single>>.>.>.>.>.>.>>\t3\n"; cout<<"\n\n\n\t\tBinary Search Multiple>>.>.>.>.>.>.>>\t4\n\t"; cout<<"\n\n\t\t EXIT >>.>.>.>.>.>.>>"; cout<<"\n\n\t\t ENTER YOUR CHOIVCE\t"; cin>>choice; switch (choice) { case 1: clrscr(); heading(); cout<<"\t Program for Linear Searching Single"; cout<<"\n\n****************************************************"; cout<<"\nEnter the item to search\t\t=\t"; cin>>item; for (int j=0; j
13

heading(); cout<<"\t Program for Linear Searching Multiple"; cout<<"\n\n****************************************************"; cout<<"\n\n Enter the item to search=\t"; cin>>item; for (j=0; j>item; beg=0, end=n-1,midpos=0; while (beg<=end) { midpos=(beg+end)/2; if (a[midpos]>item) end=midpos-1; if(a[midpos]
14

return; } } cout<<"\n\n\n\n\nitem not found"; getch(); case 4: clrscr(); heading(); cout<<"\t Program for Binary Searching Multiple Ascending"; cout<<"\n****************************************"; for (i=0; i>a[i]; } cout<<"\n\n Enter the item to search=\t"; cin>>item; beg=0, end=n-1,midpos=0; while (beg<=end) { midpos=(beg+end)/2; if (a[midpos]item) beg=midpos+1; else { count=1; i=midpos-1; while (a[i]==item) { count=count+1; a[i]=i-1; } DSA PROJECT ALGOS IMPLEMENTATION INTO C++

15

while(a[j]==item) { count=count+1; a[j]=j+1; } cout<<"\n\n\n\n\n\n\nitem found\t\t\t\t=\t"<
10. void merging() { int LBA=0,LBB=0,LBC=0,NA,NB,i=0; int D[100],B[100],C[100]; clrscr(); heading; cout << "\n\n **** MERGING OF TWO ARRAYS **** \n\n "; cout << " \n\n\n Enter the Number of Element of Array A = "; cin>> NA; while (i
11. void selectsort() { int temp; for (i=lb;i<=(n+lb)-2;i++) {int minloc=i; for(int j=i+1;j<=n+lb-1;j++) if(a[minloc]>a[j]) { minloc=j; } temp=a[minloc]; a[minloc]=a[i]; a[i]=temp; } clrscr(); heading(); cout << "\n\n\n ******** The Result is *********"; cout << "\n\n -------------------------------------"; for(int l=0;l
18

}

12. void shellsort() { int temp; int gap=(n/2); while (gap!=0) { int exchange=1; while (exchange!=0) {

exchange=0; for (int i=lb;i<=((n+lb)-1)-gap;i++) { if(a[i]>a[i+gap]) { temp=a[i]; a[i]=a[i+gap]; a[i+gap]=temp; exchange=1; } } }

gap=gap/2; } clrscr(); heading(); cout << "\n\n\n ******** The Result is *********"; cout << "\n\n -------------------------------------"; for (int l=0;l
13. void insertsort() DSA PROJECT ALGOS IMPLEMENTATION INTO C++

19

{ int temp; for(int last=lb+1;last<=n+lb-1;last++) { temp=a[last]; int ptr=last-1; while((temp=lb)) { a[ptr+1]=a[ptr]; ptr=ptr-1; } a[ptr+1]=temp;} cout << "\n\n\n ******** The Result is *********"; cout << "\n\n ______________________________________"; for(int l=0;l>.>.>.>.>.>.>>\t1\n"; cout<<"\n\n\t\t INSERTION SORT>>.>.>.>.>.>.>>\t2\n"; cout<<"\n\n\t\t SHELL SORT>>.>.>.>.>.>.>>\t3\n"; cout<<"\n\n\t\t SELECTION SORT>>.>.>.>.>.>.>>\34\n"; cout<<"\n\n\t\t Enter Your Choice\t"; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

20

cin>>choice; switch(choice) { case 1: bubblesort(); break; case 2: insertsort(); break; case 3: selectsort(); break; case 4: shellsort(); default: mmenu(); } } }

15. void bubblesort() { clrscr(); heading(); int last,temp; last=n-1; for (i=(n-2);i>lb;i--) for (j=0;j<(last-1);j++) { if (a[j] > a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

21

} last=last-1; } for (int y=0;y
16. void insertionsort() { clrscr(); heading(); int last,temp,ptr,n=10; for (last=1;last rel="nofollow">n-1;last++) { a[last]=temp; ptr=last-1; while ((temp=lb)) { ptr=ptr-1; } } a[ptr+1]=temp; for (int y=lb;y
17. void stack() { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

22

clrscr(); heading(); cout<<"\n\n\t\tEnter the no of elements in Stack b/w (1-100)\t=\t"; cin rel="nofollow">>stsize; clrscr(); heading(); cout<<"\n\n Choose option\t\n"; cout<<"\n\npushing in Stack>>.>.>.>.>.>.>>\t1\n"; cout<<"\n\npoping in stack>>.>.>.>.>.>.>>\t2"; cout<<"\n\nEXIT>>.>.>.>.>.>.>>"; cout<<"\n\n\t Enter your Choice Here\t"; cin>>choice; switch (choice) { case 1: { do { clrscr(); heading(); cout<<"\n\nEnter Element u want to insert in Stack"; cin>>item; push(); } while (top!=3); for (int i=0;i<=top;i++) cout<<"\n"<<st[i]; getch(); break; } case 2: clrscr(); heading(); pop(); DSA PROJECT ALGOS IMPLEMENTATION INTO C++

23

for (i=0;i<=top;i++) cout<<"\n"<<st[i]; getch(); break; default: mmenu(); }}

18. void push() { heading(); cout<<"\n PUSHING IN STACK\n"; if(top==3) { cout<<"\nstack is full"; return; } top=top+1; st[top]=item; }

19. void pop() { heading(); cout<<"\n POPING IN STACK\n"; if (top==-1) { cout<<"stack is empty"; return; } item=st[top]; top=top-1; }

20. void queue() DSA PROJECT ALGOS IMPLEMENTATION INTO C++

24

{ clrscr(); heading(); cout<<"\n\n\t\tEnter the no of elements in Queue b/w (1-100)\t=\t"; cin>>qsize; clrscr(); heading(); cout<<"\n\nChoose Option\n\n\t\t\t\n\n"; cout<<"\n\n\t\tinsertion in queue>>.>.>.>.>.>.>>\t1\n\n"; cout<<"\n\n\t\t deletion in queue>>.>.>.>.>.>.>>\t2\n\n"; cout<<"\n\n\t\tinsertion inCircular queue>>.>.>.>.>.>.>>\t3\n\n"; cout<<"\n\n\t\tDeletion in inCircular queue>>.>.>.>.>.>.>>\t4\n\n"; cout<<"\n\n\t\tExit>>.>.>.>.>.>.>>\n"; cout<<" \n\n\t Enter Your Choice Here\t"; cin>>choice; switch (choice) { case 1: { do { heading(); cout<<"\n\nEter the element to insert in queue"; cin>>item; qinsert(); } while (r!=9); for (int i=0;i<=r;i++) cout<<"\n"<
25

cout<<"\n"<
21. void qinsert() { heading(); cout<<"\nINSERTION IN QUEUE\n"; if(r==9) { cout<<"queue is full"; return; } if (r==-1) { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

26

f=0; r=0; } else r=r+1; q[r]=item; }

22. void qdelete() { heading(); cout<<"\n\n\n\t\t\t\tDELETION IN QUEUE\n"; cout<<"\n\n**********************************************\n\n\n\n"; if (f==-1) { cout<<"\n\n\n\t\t\t\ Queue is empty"; getch(); return; } item=q[f]; if (f==r) { f=-1; r=-1; } else f=f+1; for (i=f;i<=r;i++) cout<<"\n"<
23. void cqinsertion() { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

27

if((f==lb)&&(r==qsize+lb-1)||(r==f-1)) { cout << " \n Insertion Can Not Possible "; queue(); return; } if(r==lb-1) { r=lb; f=lb; } else if(r==(qsize+lb-1)) r=lb; else r=r+1; cq[r]=item; }

24. void cqdelete() { if(f==lb-1) { cout << " \n Deletion Can not Possible "; return; } item=cq[f]; if(f==r) { f=lb-1; r=lb-1; } else if (f==qsize+(lb-1)) f=lb; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

28

else f=f+1; cout << " \n\n\t Deletion Completed "; }

25. void linklist() { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

29

clrscr(); heading(); cout<<"\n\n Choose option\t\n"; cout<<"\n\n\t\tSINGLE LINK LIST>>.>.>.>.>.>.>>\t'1'\n\n"; cout<<"\n\n\t\tDOUBLE LINK LIST>>.>.>.>.>.>.>>\t'2'\n\n"; cout<<"\n\n\t\tEXIT>>.>.>.>.>.>.>>>>>>>>>>>>>>\t'3'\n\n"; cout<<"\n\n\t\tEnter your Choice Here\t"; cin>>choice; switch (choice) { case 1: slinklist(); linklist(); break; case 2: dlinklist(); linklist(); break; default: mmenu(); } }

26. void slinklist() { clrscr(); heading(); cout<<"\n\n Choose option\t\n\n"; cout<<"\n\n\t\t TRAVERSING>>.>.>.>.>.>.>.>.>\t'1'\n"; cout<<"\n\n\t\t INSERTION>>.>.>.>.>.>.>.>.>.\t'2'\n"; cout<<"\n\n\t\t DELETION>>.>.>.>.>.>.>.>.>.>\t'3'\n"; cout<<"\n\n\t\tEXIT>>.>.>.>.>.>.>.>.>.>.>.>>\t'4'\n"; cout<<"\n\n\t Enter your Choice Here\t"; cin>>choice; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

30

switch (choice) { case 1: sll_traverse(); break; case 2: sll_insertion(); break; case 3: sll_deletion(); break; default: mmenu(); } }

struct link { int inf; link *nxt; };

27. void sll_traverse() { clrscr(); heading(); char c; cout<<"\n\n\t\t\t\<><><><><>SINGLE LINK LIST<><><><><><><><>\n\n"; cout<<"\n\n<<<<<<>>>>>>>>>>>>><<<<<<<<<<<<<<<>>>>>>>>>><<<<<<<<<<<"; link *pre; link *str; link *past; pre=new link; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

31

cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>pre->inf; pre->nxt=NULL; str=pre; past=pre; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; c=getch(); while(c=='y') { pre=new link; heading(); cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>pre->inf; pre->nxt=NULL; past->nxt=pre; past=pre; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; c=getch(); } clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in one WAY<<<<<<<<<<<\n"; pre=str; cout<<"\n\n\t\t"<<pre->inf; while(pre->nxt!=NULL) { pre=pre->nxt; cout<<"\n\n\t\t"<<pre->inf; } getch(); }

28. void sll_insertion () { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

32

clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> INSERTION <<<<<<<<<<<\n"; cout<<"\n\n Choose option\t\n"; cout<<"\n\n\t\t AT FIRST NODE>>.>.>.>.>.>.>.>.\t'1'\n\n"; cout<<"\n\n\t\t AT LAST NODE>>.>.>.>.>.>.>.>.>\t'2'\n\n"; cout<<"\n\n\t\t BEFORE GIVEN NODE>>.>.>.>.>.>.>.>.\t'3'\n\n"; cout<<"\n\n\t\t AFTER GIVEN NODE>>.>.>.>.>.>.>.>.\t'4'\n\n"; cout<<"\n\n\t\t EXIT>>.>.>.>.>.>.>>>>>>>>>>\t'5'\n\n"; cout<<"\n\n\t\t Enter your Choice Here\t"; cin>>choice; switch (choice) { case 1: linkaf(); break; case 2: linkal(); break; case 3: linkbg(); break; case 4: linkag(); break; default: linklist(); } }

29. void linkaf() { clrscr(); DSA PROJECT ALGOS IMPLEMENTATION INTO C++

33

char c; int item; heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> INSERTION AT FIRST NODE <<<<<<<<<<<\n"; link2 *pre; link2 *str; link2 *past; pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; str=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); while(c=='y') { pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; past->next=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); } cout<<"\n\n\n\t\t>>>>>>>>>BEFORE INSERTION AT FIRST NODE <<<<<<<<<\n"; pre=str; cout<<"\n\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

34

} pre=new link2; cout<<"\n*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+\n"; cout<<"\n\nEnter the new item\t=\t"; cin>>item; pre->info=item; pre->next=str; str=pre; pre=str; cout<<"\n\n\n\t\t>>>>>>>>>>AFTER INSERTION AT FIRST NODE <<<<<<<<<<<\n"; cout<<"\n\t\t\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t\t\t"<<pre->info; } getch(); }

30. void linkal() { clrscr(); char c; int item; heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> INSERTION AT LAST NODE <<<<<<<<<<<\n"; link2 *pre; link2 *ptr1; link2 *str; link2 *past; pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

35

pre->next=NULL; str=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); while(c=='y') { pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; past->next=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); } cout<<"\n\n\n\t\t>>>>>>>>>>BEFORE INSERTION AT LAST NODE <<<<<<<<<<<\n"; pre=str; cout<<"\n\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; } pre=new link2; cout<<"\n*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+\n"; cout<<"\n\nEnter the new item\t=\t"; cin>>item; pre->info=item; pre->next=NULL; ptr1=str; while (ptr1->next!=NULL) ptr1=ptr1->next; ptr1->next=pre; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

36

pre=str; cout<<"\n\n\n\t\t>>>>>>>>>>>AFTER INSERTION AT LAST NODE <<<<<<<<<<<\n"; cout<<"\n\t\t\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t\t\t"<<pre->info; } getch(); }

31. void linkbg() { clrscr(); char c; int item,gnode; heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>> INSERTION BEFORE GIVEN NODE <<<<<<<<<<<\n"; cout<<"\n\n\t\t ENTER ONLY FIVE ELEMENTS\n\n"; link2 *pre; link2 *str; link2 *past; link2 *ptr2; link2 *ptr1; link2 *ptr; pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; str=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); while(c=='y') DSA PROJECT ALGOS IMPLEMENTATION INTO C++

37

{ pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; past->next=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); } cout<<"\n\n\n\t\t>>>>>>>>BEFORE INSERTION AT GIVEN NODE <<<<<<<<<<<\n"; pre=str; cout<<"\n\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; } getch(); ptr1=new link2; cout<<"\n*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+\n"; cout<<"\n\nEnter the new item\t=\t"; cin>>item; cout<<"\n\n Enter the Position of element b/w (1 to 4)"; cin>>gnode; if(gnode>5) { cout<<"\n ENTERED VALUE IS WRONG"; } ptr=str; for (int i=1;inext; } DSA PROJECT ALGOS IMPLEMENTATION INTO C++

38

ptr1->info=item; ptr1->next=ptr; ptr2=str; while (ptr2->next!=ptr) { ptr2=ptr2->next; } ptr2->next=ptr1; ptr=str; cout<<"\n\n\n\t\t>>>>>>>AFTER INSERTION AT BEFORE GIVEN NODE <<<<<<<\n"; cout<<"\n\t\t\t\t"<info; while(ptr->next!=NULL) { ptr=ptr->next; cout<<"\n\t\t\t\t"<info; } }

32. void linkag() { clrscr(); char c; int item,gnode; heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> INSERTION AFTER GIVEN NODE <<<<<<<<<<<\n"; cout<<"\n\n\t\t ENTER ONLY FIVE ELEMENTS\n\n"; link2 *pre; link2 *str; link2 *past; link2 *ptr2; link2 *ptr1; link2 *ptr; pre=new link2; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

39

cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; str=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); while(c=='y') { pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; past->next=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); } cout<<"\n\n\n\t\t>>>>>>>>>BEFORE INSERTION AT GIVEN NODE <<<<<<<<<<<\n"; pre=str; cout<<"\n\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; } getch(); ptr1=new link2; cout<<"\n*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+\n"; cout<<"\n\nEnter the new item\t=\t"; cin>>item; cout<<"\n\n Enter the Position of element b/w (1 to 4)"; cin>>gnode; if(gnode>5) DSA PROJECT ALGOS IMPLEMENTATION INTO C++

40

{ cout<<"\n ENTERED VALUE IS WRONG"; } ptr=str; for (int i=1;i<=gnode;i++) { ptr=ptr->next; } ptr1->info=item; ptr1->next=ptr; ptr2=str; while (ptr2->next!=ptr) { ptr2=ptr2->next; } ptr2->next=ptr1; ptr=str; cout<<"\n\n\n\t\t>>>>>>>AFTER INSERTION AT AFTER GIVEN NODE <<<<<<<\n"; cout<<"\n\t\t\t\t"<info; while(ptr->next!=NULL) { ptr=ptr->next; cout<<"\n\t\t\t\t"<info; } getch(); }

33. void sll_deletion () { clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

41

cout<<"\n\n\n\t\t>>>>>>>>>>>>> DELETION <<<<<<<<<<<\n"; cout<<"\n\n Choose option\t\n"; cout<<"\n\n\t\t AT FIRST NODE>>.>.>.>.>.>.>.>.\t'1'\n\n"; cout<<"\n\n\t\t AT LAST NODE>>.>.>.>.>.>.>.>.>\t'2'\n\n"; cout<<"\n\n\t\t AT GIVEN NODE>>.>.>.>.>.>.>.>.\t'3'\n\n"; cout<<"\n\n\t\t EXIT>>.>.>.>.>.>.>>>>>>>>>>\t'4'\n\n"; cout<<"\n\n\t\t Enter your Choice Here\t"; cin>>choice; switch (choice) { case 1: linkaf_d(); break; case 2: linkal_d(); break; case 3: linkag_d(); break; default: linklist(); } getch(); }

34. void linkaf_d() { clrscr(); char c; int item; heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> DELETION AT FIRST NODE <<<<<<<<<<<\n"; link2 *pre; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

42

link2 *ptr1; link2 *str; link2 *past; link2 *ptr; pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; str=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); while(c=='y') { pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; past->next=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); } cout<<"\n\n\n\t\t>>>>>>>>>>>BEFORE DELETION AT FIRST NODE <<<<<<<<<<<\n"; pre=str; cout<<"\n\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; } pre=new link2; cout<<"\n*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+\n"; pre=str->next; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

43

//item=pre->info; //free (pre); cout<<"\n\n\n\t\t>>>>>>>>>>>AFTER DELETION AT FIRST NODE <<<<<<<<<<<\n"; pre=str; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; } getch(); }

35. void linkal_d() { clrscr(); char c; int item; heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> DELETION AT LAST NODE <<<<<<<<<<<\n"; link2 *pre; link2 *ptr1; link2 *str; link2 *past; pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; str=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); while(c=='y') { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

44

pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; past->next=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); } cout<<"\n\n\n\t\t>>>>>>>>>>>BEFORE DELETION AT LAST NODE <<<<<<<<<<<\n"; pre=str; cout<<"\n\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; } cout<<"\n*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+\n"; pre=str; while (pre->next->next !=NULL) pre=pre->next; pre->next=ptr1; pre->next=NULL; //item=pre->info; //free (pre); cout<<"\n\n\n\t\t>>>>>>>>>>>AFTER DELETION AT FIRST NODE <<<<<<<<<<<\n"; pre=str; cout<<"\n\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; } getch(); DSA PROJECT ALGOS IMPLEMENTATION INTO C++

45

}

36. void linkag_d() { clrscr(); char c; int item,gnode; heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> SINGLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> DELETION AT GIVEN NODE <<<<<<<<<<<\n"; link2 *pre; link2 *ptr1; link2 *str; link2 *past; link2 *ptr; pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; str=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); while(c=='y') { pre=new link2; cout<<"\nEnter the list information\t=\t"; cin>>pre->info; pre->next=NULL; past->next=pre; past=pre; cout<<"Press'y' for new node or 'n'for end\n"; c=getch(); } DSA PROJECT ALGOS IMPLEMENTATION INTO C++

46

cout<<"\n\n\n\t\t>>>>>>>>>BEFORE DELETION AT GIVEN NODE <<<<<<<<<<<\n"; pre=str; cout<<"\n\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; } getch(); cout<<"\n*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+\n"; cout<<"\n\n Enter the Position of element b/w (1 to 4)"; cin>>gnode; if(gnode>5) { cout<<"\n ENTERED VALUE IS WRONG"; } ptr=str; for (int i=1;inext; } ptr1=str; while (ptr1->next!=ptr) ptr1=ptr1->next; ptr1->next=ptr->next; //item=ptr->info; //free (pre); cout<<"\n\n\n\t\t>>>>>>>>>>>AFTER DELETION AT GIVEN NODE <<<<<<<<<<<\n"; pre=str; cout<<"\n\t\t"<<pre->info; while(pre->next!=NULL) { pre=pre->next; cout<<"\n\t\t"<<pre->info; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

47

} getch(); }

37. void dlinklist() { clrscr(); heading(); cout<<"\n\n Choose option\t\n\n"; cout<<"\n\n\t\t TRAVERSING>>.>.>.>.>.>.>.>.>\t'1'\n"; cout<<"\n\n\t\t INSERTION>>.>.>.>.>.>.>.>.>.\t'2'\n"; cout<<"\n\n\t\t DELETION>>.>.>.>.>.>.>.>.>.>\t'3'\n"; cout<<"\n\n\t\tEXIT>>.>.>.>.>.>.>.>.>.>.>.>>\t'4'\n"; cout<<"\n\n\t Enter your Choice Here\t"; cin>>choice; switch (choice) { case 1: dll_traverse(); linklist(); break; case 2: dll_insertion(); break; case 3: dll_deletion(); break; default: linklist(); } DSA PROJECT ALGOS IMPLEMENTATION INTO C++

48

} struct dlink_list1 { int info; dlink_list1 *next; dlink_list1 *back; dlink_list1 *start; };

38. void dll_traverse() { clrscr(); heading(); cout<<"\n\n\t\t\t\<><><><><>DOUBLE LINK LIST<><><><><><><><>\n\n"; cout<<"\n\n<<<<<<>>>>>>>>>>>>><<<<<<<<<<<<<<<>>>>>>>>>><<<<<<<<<<<"; char choice; dlink_list *present; dlink_list *start; dlink_list *back; present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; start=present; back=present; present->next=NULL; present->previous=NULL; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); while(choice=='y') { present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; present->next=NULL; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

49

present->previous=back; back->next=present; back= present; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); } clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> DOUBLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); }

39. void dll_insertion () { clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> DOUBLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> INSERTION <<<<<<<<<<<\n"; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

50

cout<<"\n\n Choose option\t\n"; cout<<"\n\n\t\t AT FIRST NODE>>.>.>.>.>.>.>.>.\t'1'\n\n"; cout<<"\n\n\t\t AT LAST NODE>>.>.>.>.>.>.>.>.>\t'2'\n\n"; cout<<"\n\n\t\t BEFORE GIVEN NODE>>.>.>.>.>.>.>.'3'\n\n"; cout<<"\n\n\t\t AFTER GIVEN NODE>>.>.>.>.>.>.>.'4'\n\n"; cout<<"\n\n\t\t EXIT>>.>.>.>.>.>.>.>.>.>.>.>.>>>>'5'\n\n"; cout<<"\n\n\t\t Enter your Choice Here\t"; cin>>choice; switch (choice) { case 1: dll_ins_af(); dlinklist(); case 2: dll_ins_al(); dlinklist(); case 3: dll_ins_bg(); dlinklist(); case 4: dll_ins_ag(); dlinklist(); default: dlinklist(); } getch(); }

40. void dll_ins_af() { clrscr(); heading(); cout<<"\n\n\t\t\t\<><><><><>DOUBLE LINK LIST<><><><><><><><>\n\n"; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

51

cout<<"\n\n<<<<<<>>>>>>>>INSERTION AT FIRST NODE<<<<<<<<<<<<<<<>><"; char choice; int item; dlink_list *present; dlink_list *start; dlink_list *back; present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; start=present; back=present; present->next=NULL; present->previous=NULL; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); while(choice=='y') { present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; present->next=NULL; present->previous=back; back->next=present; back= present; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); } clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>BEFORE INSERTION AT FIRST NODE<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

52

cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); cout<<"\n******************************************\n"; cout<<"\n\n\t ENTER THE NEW ELEMENT\t=\t"; cin>>item; present=new dlink_list; present->info=item ; present->previous=NULL; start->previous=present; present->next=start; start=present; clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>>> AFTER INSERTION AT FIRST NODE<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

53

present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); }

41. void dll_ins_al() { clrscr(); heading(); cout<<"\n\n\t\t\t\<><><><><>DOUBLE LINK LIST<><><><><><><><>\n\n"; cout<<"\n\n<<<<<<>>>>>>>INSERTION AT LAST NODE<<<<<<<<<<<<<<<<<<"; char choice; int item; dlink_list *present; dlink_list *start; dlink_list *back; dlink_list *ptr1; present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; start=present; back=present; present->next=NULL; present->previous=NULL; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); while(choice=='y') { present=new dlink_list; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

54

cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; present->next=NULL; present->previous=back; back->next=present; back= present; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); } clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>> BEFORE INSERTION AT LAST NODE<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); cout<<"\n******************************************\n"; cout<<"\n\n\t ENTER THE NEW ELEMENT\t=\t"; cin>>item; present=new dlink_list; present->info=item ; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

55

present->next=NULL; ptr1=start; while (ptr1->next!=NULL) ptr1=ptr1->next; ptr1->next=present; present->previous=ptr1; clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>> AFTER INSERTION AT LAST NODE<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back->next; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); }

42. void dll_ins_bg() { clrscr(); heading(); cout<<"\n\n\t\t\t\<><><><><>DOUBLE LINK LIST<><><><><><><><>\n\n"; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

56

cout<<"\n\n<<<<<>>>>>>INSERTION AT BEFORE GIVEN NODE<<<<<<<<<<<<<"; char choice; int item,gnode; dlink_list *present; dlink_list *start; dlink_list *back; dlink_list *ptr1; present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; start=present; back=present; present->next=NULL; present->previous=NULL; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); while(choice=='y') { present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; present->next=NULL; present->previous=back; back->next=present; back= present; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); } clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>> BEFORE INSERTION AT BEFORE GIVEN NODE<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do DSA PROJECT ALGOS IMPLEMENTATION INTO C++

57

{ cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); present=new dlink_list; cout<<"\n******************************************\n"; cout<<"\n\n\t ENTER THE NEW ELEMENT\t=\t"; cin>>item; cout<<"\n Enter the position of new element\t=\t"; cin>>gnode; present->info=item; ptr1=start; for (int i=1;i<(gnode-1);i++) { ptr1=ptr1->next; } present->previous=ptr1; present->next=ptr1->next; ptr1->next->previous=present; ptr1->next=present; clrscr(); heading(); cout<<"\n\n\n\t\t>>>>> AFTER INSERTION AT BEFORE GIVEN NODE<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

58

present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); }

43. void dll_ins_ag() { clrscr(); heading(); cout<<"\n\n\t\t\t\<><><><><>DOUBLE LINK LIST<><><><><><><><>\n\n"; cout<<"\n\n<<<<<<>>>>>>>>INSERTION AT AFTER GIVEN NODE<<<<<<<<<<<<<"; char choice; int item,gnode; dlink_list *present; dlink_list *start; dlink_list *back; dlink_list *ptr1; present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; start=present; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

59

back=present; present->next=NULL; present->previous=NULL; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); while(choice=='y') { present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; present->next=NULL; present->previous=back; back->next=present; back= present; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); } clrscr(); heading(); cout<<"\n\n\n\t\t>>>>> BEFORE INSERTION AT AFTER GIVEN NODE<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

60

} while(present!=NULL); getch(); present=new dlink_list; cout<<"\n******************************************\n"; cout<<"\n\n\t ENTER THE NEW ELEMENT\t=\t"; cin>>item; cout<<"\n Enter the position of new element\t=\t"; cin>>gnode; present->info=item; ptr1=start; for (int i=1;inext; } present->previous=ptr1; present->next=ptr1->next; ptr1->next->previous=present; ptr1->next=present; clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>> AFTER INSERTION AT AFTER GIVEN NODE<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { DSA PROJECT ALGOS IMPLEMENTATION INTO C++

61

cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); }

44. void dll_deletion () { clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>>> DOUBLE LINK LIST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> DELETION <<<<<<<<<<<\n"; cout<<"\n\n Choose option\t\n"; cout<<"\n\n\t\t AT FIRST NODE>>.>.>.>.>.>.>.>.\t'1'\n\n"; cout<<"\n\n\t\t AT LAST NODE>>.>.>.>.>.>.>.>.>\t'2'\n\n"; cout<<"\n\n\t\t AT GIVEN NODE>>.>.>.>.>.>.>.>.\t'3'\n\n"; cout<<"\n\n\t\t EXIT>>.>.>.>.>.>.>>>>>>>>>>\t'4'\n\n"; cout<<"\n\n\t\t Enter your Choice Here\t"; cin>>choice; switch (choice) { case 1: dll_del_af(); linklist(); break; case 2: dll_del_al(); dlinklist();; case 3: dll_del_ag(); dlinklist(); default: linklist(); } DSA PROJECT ALGOS IMPLEMENTATION INTO C++

62

getch(); }

45. void dll_del_af() { clrscr(); heading(); cout<<"\n\n\t\t\t\<><><><><>DOUBLE LINK LIST<><><><><><><><>\n\n"; cout<<"\n\n<<<<<<>>>DELETION AT FIRST NODE<<<<<<<<<<<<<<<<<<<"; char choice; int item; dlink_list *present; dlink_list *start; dlink_list *back; dlink_list *ptr1; present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; start=present; back=present; present->next=NULL; present->previous=NULL; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); while(choice=='y') { present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; present->next=NULL; present->previous=back; back->next=present; back= present; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

63

choice=getch(); } clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>>BEFORE DELETION AT FIRST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); cout<<"\n******************************************\n"; ptr1=start; start->next->previous=NULL; start=start->next; item=ptr1->info; free (ptr1); clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>>>>>> AFTER DELETION AT FIRST<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do DSA PROJECT ALGOS IMPLEMENTATION INTO C++

64

{ cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); }

46. void dll_del_al() { clrscr(); heading(); cout<<"\n\n\t\t\t\<><><><><>DOUBLE LINK LIST<><><><><><><><>\n\n"; cout<<"\n\n<<<<<>>>>>>>>DELETION AT LAST NODE<<<<<<<<>><<<<<<<<<<<"; char choice; int item; dlink_list *present; dlink_list *start; dlink_list *back; dlink_list *ptr1; present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; start=present; back=present; present->next=NULL; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

65

present->previous=NULL; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); while(choice=='y') { present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; present->next=NULL; present->previous=back; back->next=present; back= present; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); } clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>>BEFORE DELETION AT LAST NODE <<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); DSA PROJECT ALGOS IMPLEMENTATION INTO C++

66

getch(); cout<<"\n******************************************\n"; ptr1=start; while (ptr1->next->next!=NULL) ptr1=ptr1->next; ptr1->next=NULL; clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>>> AFTER DELETION AT LAST NODE<<<<<<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back->previous; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); }

47. void dll_del_ag() { clrscr(); heading(); cout<<"\n\n\t\t\t\<><><><><>DOUBLE LINK LIST<><><><><><><><>\n\n"; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

67

cout<<"\n\n<>>>>>>>>>>>>>DELETION AT GIVEN NODE<<<<>><<<<<<<<<<<"; char choice; int item,gnode; dlink_list *present; dlink_list *start; dlink_list *back; dlink_list *ptr1; dlink_list *ptr; present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; start=present; back=present; present->next=NULL; present->previous=NULL; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); while(choice=='y') { present=new dlink_list; cout<<"\n\nENTER the ELEMENT in LINK list\t=\t"; cin>>present->info; present->next=NULL; present->previous=back; back->next=present; back= present; cout<<"\n\n\n For entering new element Press 'Y' otherwise 'N'\n"; choice=getch(); } clrscr(); heading(); cout<<"\n\n\n\t\t>>>>BEFORE DELETION AT GIVEN NODE <<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; DSA PROJECT ALGOS IMPLEMENTATION INTO C++

68

do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); cout<<"\n******************************************\n"; cout<<"\n Enter the position of deleting element\t=\t"; cin>>gnode; ptr1=start; for (int i=1;inext; ptr=ptr1->previous; ptr->next=ptr1->next; ptr1->next->previous=ptr; clrscr(); heading(); cout<<"\n\n\n\t\t>>>>>> AFTER DELETION AT GIVEN NODE<<<<<<<<<<<\n"; cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in FORWARD <<<<<<<<<<<\n"; present=start; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->next; } DSA PROJECT ALGOS IMPLEMENTATION INTO C++

69

while(present!=NULL); cout<<"\n\n\n\t\t>>>>>>>>>>>>> TRAVERSING in BACKWARD<<<<<<<<<<<\n"; present=back; do { cout<<"\n\n\t\t\t\t"<<present->info; present=present->previous; } while(present!=NULL); getch(); }

DSA PROJECT ALGOS IMPLEMENTATION INTO C++

70

DSA PROJECT ALGOS IMPLEMENTATION INTO C++

71

Related Documents

Dsa Proj
November 2019 21
Dsa
December 2019 14
Proj
November 2019 33
Proj
April 2020 27
Proj
December 2019 28
Proj
June 2020 20