rev->next->next = NULL;
//this line has to be there.
//Else it wont work.
//Check it once.
//If we go for the recursive function then
//why don't you have two arguments? Try the below code?
OutputList = ReverseNew(LList,NULL); //Call should be like this.
Node* ReverseNew(Node *NList, Node * Remaining)
if(NList == NULL) return Remaining;
Node *tList = NList->Next;
NList->Next = Remaining;
*** If linked list is very big, then a big stack will be created for recursive function, may cause problem.
*** Need to think, as recursive will not be a better solution. :)
reverse using recursion..
i think this if condition is wrong
if (! (n && n -> next))
it should be
if (! (n->next && n->next->next))
this is to ensure that n points to the 2nd last node. (i.e. if n->next->next is NULL we have to return n as here n is pointing to the 2nd last node and we have to start reversing links from here)
because if you return the last node as per "if (! (n && n -> next))",
n->n->next = head will crash as n->next->next is NULL..since head is aldready pointing to the last node.
so we have to ensure that n is pointing to the 2nd last node.
I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:
Runtime run = Runtime.getRuntime();
Process pr = ...
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"