I am working with simple linked lists in C # and I do not know how to add elements to the end of the list, callwood help to anyone?
Namespace console application 1 class {1 public square node () {public integer data; Next to public node; } Private node FirstNode = Faucet; Public Zero AddBefore (int number) {node NewNode = new node (); NewNode.Next = FirstNode; NewNode.Data = Number; FirstNode = NewNode; } Public Zero AddAfter (int no) {if (FirstNode == zero) {AddBefore (number); } other { ??????????????? }}
You need to repeat through your list until you get the last node , And then add it to the end something like this:
Public Zero AddAfter (int no) {if (FirstNode == zero) {AddBefore (number); } Else {// Final node node finding CurrentNode = FirstNode; While currentNode.Next.Node! =) CurrentNode = currentNode.NextNode; // Create a new node node new node = new node (); NewNode.Data = Number; NewNode.Next = Faucet; // Adding the node to the existing node. Node.NextNode = newNode; }}
Comments
Post a Comment