My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
Advertisements
|
Program of Doubly linked list using C++
Posted Date: 10 Jun 2008 Resource Type: Articles/Knowledge Sharing Category: Education
|
Posted By: Sanjana Member Level: Gold Rating: Points: 1
|
|
|
|
#include #include #define NULL 0 struct list { int data; struct list*next; struct list *prev; }; typedef struct list node; node *find(node *,int); node *pre=NULL; node *fin=NULL; node *start; int main() { int menu(void); void create(node *); void display(node *); void insert(node *,int,int); void revdisplay(node *); void del(node *,int); int choice,ch; int data,tar; node *newrec; start=NULL;
do { clrscr(); choice=menu(); switch(choice) { case '1': cout<<"\nCreating the list"; cout<<"Enter the terms(type 0 to end)\n"; start=new node; create(start); break; case '2': if (start==NULL) cout<<"\nList does not exist"; else { cout<<"\nDisplaying the list\n"; display(start); } getch(); break; case '3': if (start==NULL) { cout<<"\nList does not exist"; getch(); } else { cout<<"\nDisplaying the list:";
revdisplay(fin); case '4': if(start==NULL) { cout<<"\nList does not exist"; getch(); } else { cout<<"\nEnter the term to insert:"; cin>>data; cout<<"\nEnter target term:"; cin>>tar; insert(start,data,tar); } break; case '5': if(start==NULL) cout<<"\nlist does not exist:"; getch(); } else { cout<<"\nEnter the term to delete:"; cin>>data; del(start,data); break; case '6': cout<<"\nExiting"; break; default: cout<<"\nNot a valid choice"; getch(); break; } }while(choice!=6); getch(); return(0); } int menu(void) { int ch; cout<<"\n1->Creation of the list"; cout<<"\n2->Displaying of the list"; cout<<"\n3->Displaying the list"; cout<<"\n4->Insertion of the list"; cout<<"\n5->Deletion of the list"; cout<<"\n6->Reverse of the list"; cout<<"\n7->Exit"; cout<<"\nEnter your choice:"; cin>>ch; return(ch); } void create(node *record) { cin>>record->data; if(record->data==0) { record->next=NULL; record->prev=pre; fin=record->prev; pre=NULL; else { record->prev=pre; record->next=new node; pre=record; create(record->next); } return; } void display(node *record) { if(record->next!=NULL) { coutdisplay(record->next); } return; } void reverse(node *record) { if(record!=NULL) { coutrevdisplay(record->prev); } return; void insert(node *record,int data,int target) { node *tag,*newrec,*temp; newrec=new node; if(record->data==target) { newrec->next=record; newrec->prev=NULL; record->prev=newrec; start=newrec; } else { tag=find(record,target); temp=tag->prev; tag->prev=newrec; newrec->next=tag; temp->next=newrec; } if(tag==NULL) { cout<<"Target item not present in the list\n"; getch(); return; } newrec->data=data; return; } void del(node *record,int target) { node *tag,*temp; if(record->data==target) { temp=record; start=start->next; start->prev=NULL; delete temp; } else { tag=find(record,target); if(tag->next->next==NULL) { fin=fin->prev; fin->next=tag->next; } if(tag==NULL) { cout<<"Target item not present in the list\n"; getch(); return; } return; } node *find(node *record,int target) { if(record->next->data==target) { return(record); } else if(record->next==NULL) return(NULL); else find(record->next,target); } }
|
Responses
|
| Author: Lenin 10 Jun 2008 | Member Level: Diamond Points : 2 | girish used to post programs from C language . Now Narma has joined in that category but in a different direction using C++. Are you expert in C++. What is your profile in C++ , i mean where you are in C++. Are you a CS student. Who is the next in this category ??
| | Author: Sanjana 11 Jun 2008 | Member Level: Gold Points : 2 | hi
on behalf of ISC we have to thank girish for his contineous posting of c programs
i am not much expert in c++..i am on the way , now only i have started
let we see who comes next..
|
|
|