hi guyz.i've been working for this assignment in linked list for almost a week now..im complete making the program but i still have problem in deleting elements..in my program when i enter 1,2,3,4 and i want to delete 2..it deletes the 4 not the 2:?: ..how will i solve this?..pls help..

#include<iostream.h
int main()
{
int i=1,d,n,list[100];
char ans,z,temp;
do
{
cout<<"MENU OPTION\n";
cout<<"A.] Add\n";
cout<<"B.] Delete\n";
cout<<"C.] View list\n";
cout<<"Enter your Option: ";
cin>>z;
if(z=='a'||z=='A')
{
if(i>100)
cout<<"Error: List FULL!!\n";
else
{
cout<<"Enter value to list: ";
cin>>list[i];
i++;
}
}
else if(z=='b'||z=='B')
{
if(i==1)
cout<<"Error: No value to delete\n";
else
{
cout<<"Enter value to delete from list:";
cin>>temp;
i--;
for(d=1;d<i;d++)
{
if(temp==list[d])
list[d]=list[n];
n++;
}
}
}
else if(z=='c'|z=='C')
{
if(i==1)
cout<<"Error: Empty list!!\n";
else
{
cout<<"list of values:\n";
for(d=1;d<i;d++)
cout<<"list[d]<<Endl;
}
}
else
cout<<"Out of Range...\nInvalid Choice!!\n";
cout<<"Another Try?[y/n]";
cin>>ans;
}while(ans=='y'||ans=='Y')
return 0;
}

I've got some bad news for you. Your existing code isn't using linked lists at all. It is using an array!

Before you can delete from a linked list you need to actually create a linked list.

Here is an introduction to linked lists.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.