void insertLoc(int n, int i)
inserts a node with info n after the ith location in the list. If the ith location does not exist in the list then the program should exit with an error message.
Can anyone help me with the code please...
#include<iostream>
#include<process.h>
using namespace std;
struct node {
int info;
node *nextptr;
};
class list {
node *L,*tail;
int count;
public:
list() {
L=tail=NULL;
count=0;
}
void size();
void InsertHead(int info);
int RemoveHead();
void Print();
void insertLoc(int n, int i);
};
void list::size() {
cout<<"size is :"<<count<<endl;
}
void list::Print() {
node *p;
p=L;
cout<<"\n\n";
while(p!=NULL) {
cout<<p->info<<"\t";
p=p->nextptr;
}
}
int list::RemoveHead() {
int RemoveNode;
if(L==NULL) {
cout<<"\n\nSTACK EMPTY\n\n";
exit(1);
}
node *temp;
temp=L;
RemoveNode=L->info;
L=L->nextptr;
delete temp;
--count;
return RemoveNode;
}
void list::InsertHead(int info) {
node *n=new node;
n->info=info;
n->nextptr=L;
L=n;
++count;
}
int main() {
int choice,info;
list L;
while(1) {
cout<<"\nENTER 1 FOR INSERT\n";
cout<<"ENTER 2 FOR PRINT \n";
cout<<"ENTER 3 FOR REMOVE\n";
cout<<"ENTER 4 FOR SIZE\n";
cout<<"ENTER 5 FOR SPECIFIC LOCATON\n";
cout<<"ENTER 6 FOR EXIT\n\n";
cin>>choice;
if(choice==1) {
cout<<"\n\nENTER VALUE FOR PUSH=\t";
cin>>info;
L.InsertHead(info);
} else
if(choice==2) {
L.Print();
} else
if(choice==3) {
cout<<"REMOVE ITEM=\t"<<L.RemoveHead()<<endl;
} else
if(choice==4)
{
L.size();
}
else
if(choice==5)
{
int infoo,pos;
cout<<"Enter info value nd pos=\t";
cin>>infoo;
cin>>pos;
L.insertLoc(infoo, pos);
}
else
{
exit();
}
}
return 0;
}