CPSC 241-002 Computer Science IV
(Data Structures and Algorithms)

Fall 1998
TTh 12:30--1:45 Daniel 408
Assignment 1
<http://andrewd.ces.clemson.edu/courses/cpsc241/fall98/hw/asg1.html>

Objectives:
To learn pointer manipulation, linked lists.

Due date:
09/03/98

What to hand in:
``Professional-quality'' writeup, including:
  1. Cover page containing:
    Course Id--Section No.
    Name:
    SS No:
    Assignment No.
  2. Assignment description
  3. Solution description (e.g., program design, description of algorithm, etc., however appropriate).
  4. Lessons learned, identified interesting features of your program
  5. Appendix A: Source code listing
  6. Appendix B: Sample input (if any)
  7. Appendix C: Sample output
The entire document should be a clearly written account of what you were to accomplish, what you in fact did accomplish, and what you learned (how you accomplished it). The code and sample runs, listed in the appendices, should be clearly documented (e.g., document the source code, generate informative output).

The general presentation of your document counts! (This includes qualities such as neatness, formatting, and legibility.)

Description:
  1. Write a program to create a linked list of variable size (as indicated by the user).

  2. The user supplies only the length of the list: create and load the list iteratively (e.g., in a loop) with ascending integer values.

    Hint: you'll need three pointers to do this ``on the fly''.

  3. Use the following global list node structure:
    		struct Node {
    		  int val;
    		  struct Node *next;
    	    	};
    		
  4. Once the list has been created, print out its contents using the following routine:
    		void llPrint(struct Node *np)
    		{
    	  	  while(np) {
    	    	    cout << np->val << "\n";
    	    	    np = np->next;
    	  	  }
    		}
    		
  5. Sample output:
    		Enter ll size: 5
    		0
    		1
    		2
    		3
    		4
    		
  6. (Bonus) Write a routine to reverse the order of the linked list. Sample output:
    		Enter ll size: 5
    		4
    		3
    		2
    		1
    		0
    		
    Hint: use the following function prototype:
    		void llReverse(struct Node **np);