0

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;
}
2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by Passmark
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.