C# How do I run a Linked List's delete method from the main program? -


i have user-made linked list (no linq). have items in them want delete some.

the delete method of linked list:

public void delete(listelem elem)     {         listaelem helper = null;         listaelem prev = null;         while (helper != elem)         {             prev = helper;             helper = helper.next;         }          prev.next = elem.next;     } 

after want delete specific element list how call it?

let's class called customlinkedlist

at point in code, have instantiated class:

customlinkedlist mylist = new customlinkedlist(); 

next, you've added elements it:

listelem elem1 = new listelem(); mylist.add(elem1); 

in order delete element, have say:

mylist.delete(elem1); 

now, if want search object element has field, perhaps name? need method, define this:

public listelem find(string name){    // every item in list, 1 has name matches. } 

now can find particular item , delete it.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -