yes i understand now............
loc=temp->next->next; /* store B somewhere */
temp->next->next=temp->next->next->next; /* A-C-NULL */
Type: Posts; User: Axel
yes i understand now............
loc=temp->next->next; /* store B somewhere */
temp->next->next=temp->next->next->next; /* A-C-NULL */
ACB
loc=temp->next->next; /* store B somewhere */
temp->next->next=temp->next->next->next; /* A-C-NULL */
loc->next=temp->next; /* ACC */
temp->next=loc; /* A->B->C->NULL */
but after loc->next = temp->next;
is run do they *BOTH* contain C? or just loc->next ?
sorry i meant loc->next
so when you do:
loc->next = temp->next;
loc is NULL because of the previous lline yes?
temp->next->next = temp->next->next->next;
as with loc->next it is also null.
so i read the following line
loc->next = temp->next;
yes, i've did that but figured that it's incredibly insufficient in the long run. What happens when you have 30 fields in your node?? your code would get huge..
or is this close to what it does?
http://img120.imageshack.us/img120/7555/drawing1fu5.jpg
we start off with
loc = temp->next->next;
A | C | B
i have another bit of the code which i dont understand. It handles the case where there are 3 nodes. If i have a list containing ACB and it pass it 'C' it swaps B and C around to form ABC.
...
i think it makes sense. So you are saying after this line:
curr->next = (curr->next)->next
A and B become split (independant of each other) and then then you just insert B after a
like...
i have doubts about 2 nodes only.
well, loc->next = current;
whatevers in current (i.e. B) put it after loc->next.
since loc is at the position current->next
it makes B NULL B
here's what i mean diagrammatically.. it might help explain easier:
http://img98.imageshack.us/img98/540/testzj4.jpg
hmm ok what about:
nope, thanks anyway i have it working already. i was just trying to understand the code.
yes it does. ummm
loc = current->next; // makes loc point to A
current->next = current->next->next; // sets B->next to null so we have B NULL A
loc->next = current; // we then get A NULL...
hmm.. and what does the last line
current = loc; do ?
what if there are only 2 nodes?
i have the following code:
testNode *temp = current;
testNode *loc;
loc = current->next;
current->next = current->next->next;
loc->next = current;
ahh it was one line but so difficult. Basically i was scanning the list comparing start and start next nodes and saving them to a new list called "current". After each pass i wasn't updating start so...
i'm trying to do it with bubblesort hence i have an outer while and inner for loop.
and even so i want to scroll through the list by doing:
current = current->next;
but i also have to swap fields, once the swap is complete i get a reference to the swapped list. i also have to...
i have tried using bubble sort but it still doesn't seem to work. I know that my swap method works i simply pass the petNo i want swapped so if i want the first element in the list swapped i pass 0...
Hmm i don't get what you mean? i tried it anyway and only 2 nodes are printed out. i think the problem is i want to scan the list (with the start pointer) but if i want to swap i also have to use...
I've created the following nodes in my list:
addElement(&start, "B", 1);
addElement(&start, "D", 2);
addElement(&start, "A", 3);
addElement(&start, "C", 4);
nevermind. I got it i think :) afte the while i just checked if its end of the file or not and exited.