You are on page 1of 8

Lab Exercises 4: Linked List

LEARNING OUTCOMESS

These lab exercises is to


 Understand the problem related to linked list.
 Capable to transform the linked list problem into coding.
 Know how the coding for linked list using structure in C.
 Capable to implement the insertion at the end and middle of linked list.
 Able to write a function to delete nodes in a linked list.
 Able to write a function to delete nodes in a linked list

PROBLEM 1 : HOTEL CONFERENCE ROOM

A hotel contains 10 conference rooms, of which 4 are occupied as shown in Figure


4.1.

Room Event
Number

3 Meeting_X

5 Workshop_Y
6 Training_I

8 Conference_A

Figure 4.1
References

LAB EXERCISE 4.1

Estimate Time: 15 Minutes

Tasks:

Re-draw Figure 4.2 as a linked-list illustration based on Figure 4.1. Give your own
appropriate value for the memory address of the node.

[100] 3 Meeting_X 200

POINTER
[200]

NULL

Figure 4.2

LAB EXERCISE 4.2

Estimate Time: 15 Minutes

Tasks:

Re-draw Figure 4.2 to illustrate insert at the begin after the following operation,
 FSKKP needs one room for Workshop_J at room 2.
 The hotel allocated one room for Special_VVIP occasion at room 10.

LAB EXERCISE 4.3

Estimate Time: 1 Hour

Tasks:

Build a complete C program to represent the list of event. Your program must be
developed based on your illustration in Exercise 4.1 – 4.2. The program must be
capable to handle user input from keyboard and using insertion at the begin of the
list. The final output of your program is as shown in Figure 4.3.
References

e - Enter new event


l - List all event
x - Exit

Enter choice: l
Room number Event

10 VVIP

2 Workshop_J

3 Meeting_X

5 Workshop_Y

8 Training_I

6 Conference_A

Figure 4.3

PROBLEM 2 : CLINIC TREATMENT ROOM

A clinic contains 8 rooms, of which 4 are occupied as shown in Figure 4.4.

Room Patient
number number
1 3001

3 1001
4 2001

6 5001

Figure 4.4
References

LAB EXERCISE 4.4

Estimate Time: 15 Minutes

Tasks:

Re-draw Figure 4.5 as a linked-list illustration based on Figure 4.4. Give your own
appropriate value for the memory address of the node.

[100] 1 3001 400

POINTER

NULL

Figure 4.5

LAB EXERCISE 4.5

Estimate Time: 15 Minutes

Tasks:
Re-draw Figure 4.5 to illustrate insert at the end after the following operation,
 Patient no 3002 enter the room number 7
 Patient no 1002 enter the room number 8

[100] 1 3001 400

400 3 1001 600

600 4 2001 700

700 5001 NULL

600 7 3002 900

LAB EXERCISE 4.6 900 8 1002 NULL


References

Estimate Time: 30 Minutes

Tasks:

Build a complete C program to represent the list of patients’ number. Your program
must be developed based on your illustration in Exercise 4.4 – 4.5. The program must
be capable to handle user input from keyboard and using insertion at the end of the
list. The final output of your program is as Figure 4.6.

e - Enter new patient’s number


l - List all patients
x - Exit

Enter choice: l

Room Number Patient Number

1 3001

3 1001

4 2001

6 5001

7 3002

8 1002

Figure 4.6

LAB EXERCISE 4.7

Estimate Time: 15 Minutes

Tasks:

Re-draw Figure 4.5 to illustrate insert at the middle after the following operation,
 Patient no 2002 enter the room number 2
 Patient no 5002 enter the room number 5
References

LAB EXERCISE 4.8

Estimate Time: 30 Minutes

Tasks:

Build a complete C program to represent the list of patients’ number. Your program
must be developed based on your illustration in Exercise 4.7. The program is capable
to handle user input from keyboard and using insertion at the middle of the list.
Upon request from user, the program will ask user to enter the location of new
patient. The final output of your program is as Figure 4.7.

e - Enter new patient’s number


l - List all patients
x - Exit

Enter choice: l

Room Number Patient Number

1 3001

2 2002

3 1001

4 2001

5 5002

6 5001

Figure 4.7

PROBLEM 3 : HOSTEL ROOM


References

Level 1 in block A at UMP hostel contains 15 rooms, of which are 7 occupied as


shown in Figure 4.8.

Room Student
number
1 Lucy
2 Tisha

5 Tania

7 Ida
8 Sara

10 Mona

12 Nadia

Figure 4.8

LAB EXERCISE 4.9

Estimate Time: 30 Minutes

Tasks:

Based on Figure 4.8, build a complete linked list program to represent the list of
students. Create a function to input and display the information. For this task,
construct a function to delete a node at the begin of the list.

LAB EXERCISE 4.10

Estimate Time: 30 Minutes

Tasks:

Save your program in Exercise 4.9 as another file name. Replace your previous delete
node function with a function to delete a node at the end of the list.

LAB EXERCISE 4.11


References

Estimate Time: 30 Minutes

Tasks:

Save your program in Exercise 4.10 as another file name. Replace your previous
delete node function with a function to delete a node at the middle of the list.

You might also like