DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   linked list..quick question (http://www.daniweb.com/forums/thread37699.html)

bbbilkkk Jan 7th, 2006 7:57 pm
linked list..quick question
 
i was wondering how to delete an element or replace an element from a linked list

jwenting Jan 8th, 2006 3:52 am
Re: linked list..quick question
 
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.

typedef struct ll {
  int val;
  ll *next;
}

ll *list;

void addElement(int el) {
}

void deleteElement(int pos) {
 // find position
 // ...
 ll element = (listCopy->next)*;
 ll delElement = (element->next)*;
 element.next = delElement.next;
 delElement.next = null;
}

or something like that, my pointer code in C is a bit rusty.


All times are GMT -4. The time now is 6:34 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC