0% found this document useful (0 votes)
12 views1 page

TD - Linked Lists

Uploaded by

yahia.gueraichi
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)
12 views1 page

TD - Linked Lists

Uploaded by

yahia.gueraichi
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/ 1

NHSM - 2023/2024 ASD II

Worksheet 02: Linked lists.


For all the exercises that follow, write the solutions in C language.
We always consider linked lists of real numbers.

Exercise 1:
Write a program that:
• Reads an integer N (N<=16),
• Reads N real values and stores them in an array.
• Copies the contents of this array into a linked list.
• Sorts the linked list in ascending order.
• Copy the contents of the list into another array.
Write functions that:
• Insert an element at the kth position in the list.
• Inserts an element at the penultimate position of the list.
• Removes the penultimate item from the list.
• Removes the kth item from the list.
For all of these functions, write a main program that allows to test them with several examples.

Exercise 2:
Write a function that reverses the order in the previous list.
Exercise 3:
Write a function that inserts a list L1 at the beginning of another list L2.
Exercise 4:
Write a function that inserts a list L1 at the end of another list L2.
Exercise 5:
Write a function that inserts a list L1 into another sorted list L2. The list L2 must remain sorted.
Exercise 6:
Write a C program in which:
• You declare a doubly linked list (e.g. bidirectional) of real numbers, as depicted in the
following figure:

• You create and fill the list.


• You write functions for the following operations:
- Insert (delete) a new item at (from) the beginning;
- Insert (delete) a new item at (from) the end;
- Insert a new item at the kth position of the list;
- Find the pointer to the middle of the list;
- Delete the whole list using the pointer of item in the middle.

You might also like