0% found this document useful (0 votes)
13 views2 pages

Lab Sheet 12

Uploaded by

f20230568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Lab Sheet 12

Uploaded by

f20230568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI (RAJ.

)
CS F111 Computer Programming
LAB SESSION #12
(Linked Lists)

Q1. Create a linked list to store floating-point values. Use pointers and dynamic memory
allocation. Implement the following functions:

• createNewList: initializes a new linked list and returns it.


• createNewNode: creates a new linked list node for an element passed to it and returns
the node.
• insertNodeAtStart: inserts a node at the beginning of the list
• insertNodeAtEnd: inserts a node at the end of the list
• insertNodeAfterElem: inserts a node after a specific element in the list
• removeNodeAtStart: removes first node of the list
• removeNodeAtEnd: removes last node of the list
• removeElement: removes the node containing an element passed as argument
• printList: prints all the elements contained in the list
• find: finds whether a given element exists in the list or not

Follow the implementation explained in the slides for each of the above functions. For each
function, use a similar set of function parameters and return type as explained in the
slides. Also, follow the same way as the main() function calls these functions. If some function
is not implemented on the slides, you can appropriately decide the function parameters for it
and complete its implementation.

Create multiple header (.h) and source (.c) files to keep the program modular. Have all the
global variables and function declarations in linkedList.h. The implementations of all the
functions can be in linkedList.c. The main function can be in main.c where you can create a
linked list, append nodes to it, remove nodes from it, etc. using appropriate function calls that
are defined in linkedList.c. Follow the main function implementation as explained in the slides.
Also, give a script file to compile, link and execute the project.

Q2. Instead of storing float values in the linked list, you should now store student records
containing the attributes: ID (char array), Name (char array), Dept (char array), math_marks
(integer), phy_marks (integer), chem_marks (integer). Then implement the following functions
with specifications as follows:

• createNewList: initializes a new linked list for storing student records


• createNewNode: creates a new linked list node that can store a student record taken as
paramenter
• insertNodeAtStart: inserts a node containing a student record at the beginning of the
list
• insertNodeAtEnd: inserts a node containing a student record at the end of the list
• insertNodeAfterElem: inserts a node after a specific element in the list. That specific
element can be identified with the ID of the student record. This function must take
that student ID as an input parameter along with a new node to insert.
• removeNodeAtStart: removes first node of the list
• removeNodeAtEnd: removes last node of the list
• removeElement: removes the node containing a student record identified by an ID.
That ID must be taken as an input parameter, along with other parameters.
• printList: prints all the elements contained in the list. Note that each element is a
student record. So create a separate function printStudentRecord that taken a
student record and prints it. printList can simply call printStudentRecord to print the
students records stored in the linked list.
• find: finds whether a student with given ID exists in the linked list or not

Create multiple header (.h) and source (.c) files to keep the program modular. Have all the
global variables and function declarations in linkedList_Student.h. The implementations of
all the functions can be in linkedList_Student.c. The main function can be in
main_StudentList.c where you can create a linked list, append nodes to it, remove nodes
from it using appropriate function calls that are defined in linkedList_Student.c. Also give a
script file to compile, link and execute the project.

You might also like