Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
Link List

Link List

Ratings: (0)|Views: 8 |Likes:
Published by Ravindra Kansotia

More info:

Published by: Ravindra Kansotia on Oct 25, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

10/25/2011

pdf

text

original

 
#include<iostream>//Linklist using Structusing namespace std;struct node{int data;int key;node* next;};class LinkList{private:node* head;public:LinkList(){head=NULL;}void InsertFromStarting(int inputData);void InsertToEnd(int inputData);void Display();//Display all data of linklistvoid DeleteFromStarting();void DeleteFromEnd();};void LinkList::InsertFromStarting(int inputData){node *addNode;addNode=new node();addNode->data =inputData;addNode->next =head;head=addNode;}void LinkList::InsertToEnd(int inputData){node *addNode,*temp;temp=head;addNode=new node();addNode->data =inputData;addNode->next =NULL;if(head==NULL) head=addNode;else{while(temp->next!=NULL){temp=temp->next;}temp->next=addNode;}}void LinkList::Display(){node *temp;temp=head;if(head==NULL) cout<<"Linklist is Empty\n";else{cout<<"LinkList is = ";while(temp->next!=NULL){cout<<temp->data<<" ";temp=temp->next;}cout<<temp->data<<endl;}}
 
void LinkList::DeleteFromStarting(){node *temp;temp=head;int tempData;if(head==NULL) cout<<"Linkist is already Empty\n";else if(head->next==NULL){tempData=head->data;delete head;head=NULL;cout<<"Linkist is now Empty and deleted data is "<<tempData<<endl;}else{tempData=head->data;head=head->next;delete temp;cout<<"deleted data is "<<tempData<<endl;}}void LinkList::DeleteFromEnd(){int tempData;if(head==NULL) cout<<"Linkist is already Empty\n";else if(head->next==NULL){tempData=head->data;delete head;head=NULL;cout<<"Linkist is now Empty and deleted data is "<<tempData<<endl;}else{node *temp1,*temp2;temp1=head;temp2=temp1->next;while(temp2->next!=NULL){temp1=temp2;temp2=temp2->next;}temp1->next=NULL;tempData=temp2->data;delete temp2;cout<<"deleted data is "<<tempData<<endl;}}int main(){LinkList obj;int count;int input;cout<<"Welcome to the Linklist"<<endl;cout<<"Enter integer \n 0 for option Exit,\n 1 for option Insert fromstarting,\n 2 for option Insert to the end,"<<endl;cout<<" 3 for option Display,\n 4 for option Delete from starting,\n5 for option Delete from the end"<<endl;cin>>count;while(count!=0){switch(count){case 0:exit(0);break;case 1:

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->