Linked List Lab

In this lab you will perform several tasks on a linked list. Copy the program shell "listtest.cpp" and complete the following functions. Be sure to test your code with empty lists, lists containing just one node, and lists containing more than one node.

	struct node
	{
	     int info;
	     node* next;
	     node(int D, node *N)
	     :  info(D),
	        next(N)
	     {  }
	};
  1. void createList(node* &head);
    // Build a linked list of integers, inserting each new node at the front.
    // Enter the data from the keyboard, after deciding how many.

  2. void printList(const node* & head);
    // Write a nondestructive print that displays the data stored in the list.

  3. int countNodes(const node* & head);
    // Return the numbers of nodes contained in the list.

  4. bool inOrder(const node* & head);
    // Return true if a list is in ascending order and return false if it is not

  5. void deleteEnds(node* & head);
    // Delete the two ends of a list that contains more than one node

  6. void rotate(node* & head);
    // Split off the first node of a nonempty list and append it to the end. Do this by
    // rearranging pointers, not by allocating new nodes or moving data between nodes.

  7. Bonus! Modify the program to include the option of deleting every node that contains an odd integer. Be sure that your modifications to the program are written in the style of the other functions.

    void deleteOdds(node* &head);
    // Delete every node containing an odd integer.


Continue to:  Unit 6  / Prev  / Next