### Programming Exercise 3

Singly Linked List Implementation and Application

1. Purpose

The purpose of this exercise is to make the students familiar with:

(1) the implementation of basic operations of singly linked list;

(2) the basic application of singly linked list;

（1） The full mark is 100, which is equivalent to 5 points in the final score of this course.

（2） The assessment is based on the correctness and quality of the code, the ability demonstrated in debugging and answering related questions raised by the lecturer and teaching assistants.

（3） The exercises should be completed individually and independently.

（4） Some reference codes are provided at the end of this document, only for the purpose of helping those students who really have difficulties in programing. It is allowed to use the reference codes. However, straight copy from the reference codes or with minor modification can only guarantee you to get a pass score. Therefore, the students are encouraged to write their own codes to get a higher score.

3. Contents of Exercises

3.1 Implementation of basic operations of singly linked list

Exercise 3.1 (60 points)

Create a singly linked list with some data elements, and finish such operations as   initialization, insertion, deletion etc.

All operations should be implemented as independent functions, which can be called by the main function.

(1) Create a singly linked list with data elements of 21, 18, 30, 75, 42, 56, and output all the elements

(2) Get the length of the list, and output the value;

(3) Get the 3rd element of the list, and output the value;

(4) Insert 67 into the list at positon 3, and then output all the elements in the list;

(5) Delete the 2nd element from the list, and then output all the elements in the list;

(6) Search for 30 in the list. If found, report the position of the element;

3.2 Application of singly linked list

Exercise 3.2(20 points)

Based on the singly linked list created in step(1) of Exercise 3.1, complete following tasks:

(1) Get the maximum data element in the list, and print the maximum data;

(2) Test whether the list is in ascending order;

Exercise 3.3 (20 points)

Create a singly linked list with head node and with date elements as 10, 21,32,43,54, 65, 76, and complete following tasks:

(1) Insert 35 into the list, and keep the list in ascending order;

(2) Delete all the elements whose data value are between 22 and 57