Deleting In Linked List..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 1
Reputation: rash89 is an unknown quantity at this point 
Solved Threads: 0
rash89's Avatar
rash89 rash89 is offline Offline
Newbie Poster

Deleting In Linked List..

 
0
  #1
Jan 24th, 2008
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..
  1. #include<iostream.h
  2. int main()
  3. {
  4. int i=1,d,n,list[100];
  5. char ans,z,temp;
  6. do
  7. {
  8. cout<<"MENU OPTION\n";
  9. cout<<"A.] Add\n";
  10. cout<<"B.] Delete\n";
  11. cout<<"C.] View list\n";
  12. cout<<"Enter your Option: ";
  13. cin>>z;
  14. if(z=='a'||z=='A')
  15. {
  16. if(i>100)
  17. cout<<"Error: List FULL!!\n";
  18. else
  19. {
  20. cout<<"Enter value to list: ";
  21. cin>>list[i];
  22. i++;
  23. }
  24. }
  25. else if(z=='b'||z=='B')
  26. {
  27. if(i==1)
  28. cout<<"Error: No value to delete\n";
  29. else
  30. {
  31. cout<<"Enter value to delete from list:";
  32. cin>>temp;
  33. i--;
  34. for(d=1;d<i;d++)
  35. {
  36. if(temp==list[d])
  37. list[d]=list[n];
  38. n++;
  39. }
  40. }
  41. }
  42. else if(z=='c'|z=='C')
  43. {
  44. if(i==1)
  45. cout<<"Error: Empty list!!\n";
  46. else
  47. {
  48. cout<<"list of values:\n";
  49. for(d=1;d<i;d++)
  50. cout<<"list[d]<<Endl;
  51. }
  52. }
  53. else
  54. cout<<"Out of Range...\nInvalid Choice!!\n";
  55. cout<<"Another Try?[y/n]";
  56. cin>>ans;
  57. }while(ans=='y'||ans=='Y')
  58. return 0;
  59. }
  60.  
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 31
Reputation: Passmark is an unknown quantity at this point 
Solved Threads: 0
Passmark's Avatar
Passmark Passmark is offline Offline
Light Poster

Re: Deleting In Linked List..

 
0
  #2
Jan 24th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC