#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
struct stock
{
int data;
struct stock *next;
}*nnode,*ptr,*p,*prev,*start;
class LinkedList
{
public:
LinkedList()
{
start=NULL;
}
void create()
{
nnode=new stock;
cout<<“enter the data you want to enter”;
cin>>nnode->data;
nnode->next=NULL;
start=nnode;
}
void addAtBeginning()
{
nnode=new stock;
cout<<“enter the data you want to enter”;
cin>>nnode->data;
nnode->next=start;
start=nnode;
}
void addAtLast()
{
for(ptr=start;ptr!=NULL;prev=ptr,ptr=ptr->next);
cout<<“enter the data you want to enter”;
nnode=new stock;
cin>>ptr->data;
prev->next=nnode;
nnode->next=NULL;
}
void deleteFirst()
{
ptr=start;
start=ptr->next;
delete(ptr);
}
void deleteLast()
{
for(ptr=start;ptr!=NULL;p=prev,prev=ptr,ptr=ptr->next);
p->next=NULL;
delete(prev);
}
void display()
{
for(ptr=start;ptr!=NULL;ptr=ptr->next)
cout<<ptr->data;
}
void addAtParticularPosition()
{
cout<<“Enter the location at which you want thenode to inserted”;
cin>>location;
if(location>totalNumberOfNodes() ||location<0)
{
cout<<“Invalid location”;
else
}
}
void deleteAtParticularPositon()
{
cout<<“Enter the location at which you wantthe node to inserted”;
cin>>location;
if(location>totalNumberOfNodes() ||location<0)
{
cout<<“Invalid location”;
else
}
}
};
int main()
{
int ch;
LinkedList l;
clrscr();
while(1)
{
cout<<“enter choice”;
cin>>ch;
switch(ch)
{
case 1:l.create();
break;
case 2:l.addAtBeginning();
break;
case 3:l.addAtLast();
break;
case 4:l.deleteFirst();
break;
case 5:l.deleteLast();
break;
case 6:l.display();
break;
case 7:l.totalNumberOfNodes();
break;
case 8: exit(1);
case 9:l.addAtParticularPosition();
break;
case 10:l.deleteAtParticularPositon();
break;
default:cout<<“invalid choice”;
}
}
getch();
return 0;
}
Please complete the voidaddAtParticularPosition() function to add any node at anydesired position considering it should add first node or last nodeor any node
PayPal Gateway not configured
PayPal Gateway not configured