In order to create a linked list manually using recursive methods, I can not understand why my involvement before the method The new node is inserted. The list has not been resolved. I'm new to this and any help would be appreciated why this is happening.
My node class
class Csc2001Node {protected four b; Protected Csc2001Node Next; / * * Build a Csc2001Node with the given character value * @ Pal C - Character * / Public Csc2001Node (char c) {this.ch = c; This.next = null; }}
My methods from the linked list class
/ * * prints consistently in a list of characters * @ Param was on the current list of heads * @ Return current list * / Private string recursePrintList (Csc2001Node head) {If (head == blank) return "list is empty \ n"; Other (head.next! = Null) {return head.ch + "\ n" + recurs print list (head.next); } Return head.ch + "\ n"; } / * * Wrapper method for printing list * @ return a list as a string / / public records list () {System.out.print (recursePrintList (head)); } / * * Inserts a character before the first occurrence of any other specified * character in the list * * / insert public Csc2001 node (first key key, CSC 2001 node head, four from undersort) {if (head == Blank) {return head = new CSC 2001 node (toInsert); } And if (head.ch == key) returns the new Csc2001Node (toInsert); Second head.next = insertBefore (key, head.next, toInsert); Return head; } / * * Rapper method (four targets, four INNSRT) {head = insertBefore (target, head, toInsert) to insert a character before another; }
the output of what is happening
adding letters A, S, T, E, R and list Easter to the list if the test Do the character is in the R list, print out yes, if it is and otherwise yes is not printing the value of the size of this list 6 is trying to insert the Y before the list and print the list Trying and printing the value of Y size in front of the 3 list for this list Trying to insert V before and list V
Else if (head.ch == key) back to new Csc2001Node (toInsert);
Puting new characters in the list as the last element and your list is finished. You need something
else if (head.next.ch.equals (key)) {nextNode = head.next; Head.next = New Csc2001Node (toInsert); Head.next.next = nextNode; }
No comments:
Post a Comment