Quiz 3


21 July

Write the code that corresponds to the following linked list manipulation diagrams:

Initial: Head -> [ ] -> [ ] -> |
                  ^
                  |
                  p    n -> [ ]

Step 1 : Head -> [  ] ---> [  ] -> |
                  /\        /\
                  |         |
                  p   n -> [ ]                

Step 2 : Head -> [  ]-----+ [   ] -> |
                  /\      |  /\
                  |       \/ |
                  p   n->[     ]                

Solution

n->Next = p->Next;
p->Next = n;

Last updated : 21 July 2000 11.12am