HELP with a linked list problem.

List1 is a pointer to the first node in a linked list. List2 is a pointer to
the first node in a second list. q points to a node in the first linked list.
The initial segment of the first list, that is all the nodes up to and
including the one pointed to by q are to be removed and this segment put onto
the beginning of the second list while the order of the nodes in the initial
segment is maintained. If neither q nor list1 is NIL, then this task is correctly
performed by which of the following program segments, where p is a pointer?

1. q^.Next := List2;
List2 := List1;
List1 := q^.Next;

2. while List1 <> q^.Next do
p := List1;
List1 := List1^.Next;
p^.Next := List2;
List2 := p

3. p := q^.Next;
q^.Next := List2;
List2 := List1;
List2 := p;

a: none
b: 3 only
c: 1 and 3
d: 2 and 3 only
e: 1, 2 and 3

I chose #2. Because there is no pointer p in #1 and List2 := List1 in #3 does
not make since (to me). BUT! #2 by itself is not a choice. Please HELP and
Thank You in advance!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!