These are the 4 functions include KiostreamP using namespace


These are the 4 functions

#include KiostreamP using namespace std; stuct godeType. int info; aodeNype link; void createList(nodeType*& first, nodeType & last); void printList nodeType & first int main(0 nodeType first, last unt numi greateList first, last) printList(first); SystemC PAUSE\"); return 0; void createList nodeType & first, nodeType & last) int number; nodeType *newNode;

Solution

//EXAMPLE PROGRAM FOR SINGLE LINKED LIST
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
struct node
{
int number;
node *next;
};
class singlelist
{
node *first,*prev,*temp,*curr;
public:
singlelist()
{
first=NULL;
}
void create()
{
cout<<\"Stop by -999\"<<endl;
temp=new node;
cout<<\"Enter the numbers \";
cin>>temp->number;
while(temp->number!=-999)
{
   temp->next=NULL;
   if(first==NULL)
   {
   first=temp;
   prev=first;
   }
   else
   {
   prev->next=temp;
   prev=temp;
   }
temp=new node;
cin>>temp->number;
} //end of while
}

void deletenode()
{
int num;
cout<<\"\ Enter the number to delete \";
cin>>num;
if(first->number==num)
{
first=first->next;
return;
}
else
{
prev=first;
curr=first->next;
while(curr->next!=NULL)
{
if(curr->number==num)
{
prev->next=curr->next;
return;
}
prev=curr;
curr=curr->next;
}
}
if(curr->number==num)
{
prev->next=NULL;
return;
}
cout<<\"\ No such number\";
}

void insertbefore()
{
int nu;
temp=new node;
cout<<\"\ Enter the number \";
cin>>temp->number;
cout<<\"\ before the number \";
cin>>nu;
temp->next=NULL;
prev=first;
curr=first;
/* if(first==NULL) //if the list is empty then we can insert in this way
{
first=temp;
return;
}*/
if(curr->number==nu)
{
temp->next=first;
first=temp;
return;
}
else
{
prev=curr;
curr=curr->next;
while(curr->next!=NULL)
{
if(curr->number==nu)
{
prev->next=temp;
temp->next=curr;
return;
}
prev=curr;
curr=curr->next;
}
}
if(curr->number==nu)
{
prev->next=temp;
temp->next=curr;
return;
}
cout<<\"\ No such number \";
}

void insertafter()
{
int nu;
temp=new node;
cout<<\"\ Enter the number \";
cin>>temp->number;
cout<<\"\ After the number \";
cin>>nu;
temp->next=NULL;
prev=first;
curr=first;
/* if(first==NULL) //if the list is empty then we can insert in this way
{
first=temp;
return;
}*/
if(curr->number==nu)
{
temp->next=first->next;
first->next=temp;
return;
}
else
{
prev=curr;
curr=curr->next;
while(curr->next!=NULL)
{
if(curr->number==nu)
{
temp->next=curr->next;
curr->next=temp;
return;
}
prev=curr;
curr=curr->next;
}
}
if(curr->number==nu)
{
curr->next=temp;
temp->next=NULL;
return;
}
cout<<\"\ No such number \";
}

void print()
{
cout<<\" The list is \"<<endl;
cout<<\" ----------- \"<<endl;
temp=first;
while(temp!=NULL)
{
cout<<temp->number<<\"-->\";
temp=temp->next;
}
cout<<\"Nil\"<<endl;
getch();
}
};

void main()
{
int ch=0;
singlelist s;
clrscr();
cout<<\" Linked List creation \ \";
s.create();
clrscr();
while(ch!=5)
{
clrscr();
cout<<\"\ 1.Insert Before\";
cout<<\"\ 2.Insert After\";
cout<<\"\ 3.Delete \";
cout<<\"\ 4.Print \";
cout<<\"\ 5.Exit \";
cout<<\"\ Enter your choice \";
cin>>ch;
switch(ch)
{
   case 1:
       s.insertbefore();
       s.print();
       break;
   case 2:
       s.insertafter();
       s.print();
       break;
   case 3:
       s.deletenode();
       s.print();
       break;
   case 4:
       s.print();
       break;
   case 5:
       s.print();
       exit(1);
}
}
getch();
}

 These are the 4 functions #include KiostreamP using namespace std; stuct godeType. int info; aodeNype link; void createList(nodeType*& first, nodeType &
 These are the 4 functions #include KiostreamP using namespace std; stuct godeType. int info; aodeNype link; void createList(nodeType*& first, nodeType &
 These are the 4 functions #include KiostreamP using namespace std; stuct godeType. int info; aodeNype link; void createList(nodeType*& first, nodeType &
 These are the 4 functions #include KiostreamP using namespace std; stuct godeType. int info; aodeNype link; void createList(nodeType*& first, nodeType &

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site