CS210
Optional Practice on Pointers and Linked Lists
1. Given that first points to a linked list of nodes of type ElementType, write code fragments to perform these tasks:
1. Count the number of items in the list.
2. Make last point to the last node in the list, or NULL if the list is empty.
3. Remove the first node from the list.
2. Write a function, prev_ptr, which returns a
pointer to the node immediately before the node pointed to by its parameter.
3. (Bonus) Write a function to reverse the nodes of a linked list "in
place". That is, you create no new nodes- just rearrange the pointers to
existing nodes.
4. What is happening in disguised form in the highlighted statement in the
following code fragment:
Node N1(2), *p;
p = & N1;
// ..several statements
N1 = *p;
5. Draw a diagram to illustrate the configuration of nodes that is created by the following statements: (assume the definition: typedef int ElementType;)
Node *head= new Node;
head->data = 33;
Node *last = head;
Node *temp = new Node(14);
last->next = temp;
last = temp;
temp = last->next = new Node(24,head);
![]()