linked list..quick question

Reply

Join Date: Jan 2006
Posts: 2
Reputation: bbbilkkk is an unknown quantity at this point 
Solved Threads: 0
bbbilkkk bbbilkkk is offline Offline
Newbie Poster

linked list..quick question

 
0
  #1
Jan 7th, 2006
i was wondering how to delete an element or replace an element from a linked list
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,144
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: linked list..quick question

 
0
  #2
Jan 8th, 2006
check any of the thousands of explanations on how to implement a linked list that exist.
Basically just point the element before the one that is to be deleted to the one that the element you're deleting is pointing to and set the pointer in that element to null.

  1. typedef struct ll {
  2. int val;
  3. ll *next;
  4. }
  5.  
  6. ll *list;
  7.  
  8. void addElement(int el) {
  9. }
  10.  
  11. void deleteElement(int pos) {
  12. // find position
  13. // ...
  14. ll element = (listCopy->next)*;
  15. ll delElement = (element->next)*;
  16. element.next = delElement.next;
  17. delElement.next = null;
  18. }

or something like that, my pointer code in C is a bit rusty.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
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