Homework 8


Due : 9.30am, 19 July

For this homework, you may assume the type definitions used in class today or the following complete/simplified version:

struct NodeType {
   int i;
   NodeType *Next;
};

  1. Write code to add a node at the head of an empty list
    (ie initially, assume Head -> |)
  2. Write code to add a node at the head of a list with exactly one node
    (ie, initially, assume Head -> [] -> |)

Solution

  1. (Head = new NodeType)->Next = NULL;
    
  2. NodeType *n = new NodeType;
    n->Next = Head;
    Head = n;
    

Last updated : 18 July 2000 12.31pm