CS 102 (Fall '03)
[Schedule]
[Examples] [Programs]
[Notes & Reference]
[Syllabus] [Lab
& TA] [Tests]
[Grades]
See this example (MS Word) of using an array of structs to store characters in order. This handout includes an example program that illustrates how instead of using an array of structs, we can dynamically allocate structs to do the same thing.
listprog.cpp
Creating a linked list of numbers, and then finding the sum of the numbers. After you understand that part of the program, then take a look at the functions that use recursion to reverse the order of the list. You'll need to do a careful trace on paper of a small list (e.g. 3 nodes) to keep track of how it works.
If you want to take the code that adds a node to the list and put that code inside of a function, you will need to use a reference parameter to allow the head pointer of the list to change. See listprog3.cpp for this code.
For a version that uses C++ classes instead of a struct, see listprog2.cpplinkedList.cpp
A generic program showing how to use a linked list of numbers. Based on the code given in Chapter 10 of Johnsonbaugh and Kalin's Applications Programming in C textbook. Compare to the straight C version.listInsert.c
Inserting numbers into a linked list in order.reverseList.cpp
Enter numbers into a linked list, then recursively reverse the list. See accompanying handout (doc).mazeList.cpp
Code to allow moving through a maze, using a linked list to store moves.
storeWords1.c
Storing words into an array of structs, where space is all allocated statically.
storeWords2.c
Storing words into an array of structs. Space is now allocated dynamically.
storeWords3.c
Linked list of words.
storeWords4.c
Linked list of words, storing words into the list from within a function
[CS Dept] [UIC]
[Prof. Reed]