Link Lists


Here's a picture of a link-list.


 

 

 
Each link in the link list is a structure which contains (besides other data) a pointer to another structure of the same type (struct *). Each "struct *" points to the next link in the link list. Each link must be allocated using the malloc( ) function.

Here's an example program that creates a link list of TS cases.
 

Here's how LinkListExample.c runs:

UNIX prompt >> a.out
Enter customer's last name: Tyler
Enter Case ID : 123456
Enter status (no gaps) : open

 
Here's the Link List
####################
Tyler
123456
open
####################

 
Options:
(1) Add another case to the front the Link-List.
(2) Remove a case from the Link-List.
(3) Quit!

Select an option: 1

Enter customer's last name: Jordan
Enter Case ID : 197628
Enter status (no gaps) : open

 
Here's the Link List
####################
Jordan
197628
open

Tyler
123456
open
####################

 
Options:
(1) Add another case to the front the Link-List.
(2) Remove a case from the Link-List.
(3) Quit!

Select an option: 1

Enter customer's last name: Brutus
Enter Case ID : 161568
Enter status (no gaps) : closed

 
Here's the Link List
####################
Brutus
161568
closed

Jordan
197628
open

Tyler
123456
open
####################

 
Options:
(1) Add another case to the front the Link-List.
(2) Remove a case from the Link-List.
(3) Quit!

Select an option: 2

Enter customer's last name: Brutus
Enter Case ID : 161568
Enter status (no gaps) : closed

 
Here's the Link List
####################
Jordan
197628
open

Tyler
123456
open
####################

Options:
(1) Add another case to the front the Link-List.
(2) Remove a case from the Link-List.
(3) Quit!
Select an option: 2

 
Here's the Link List
####################
Tyler
123456
open
####################

Options:
(1) Add another case to the front the Link-List.
(2) Remove a case from the Link-List.
(3) Quit!
Select an option: 3

UNIX prompt >>

 
Here's what's happening behind the scene (in memory) while executing this program