[go: up one dir, main page]

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

TD 4 Linked List

The document outlines a tutorial module for Algorithms and Data Structures at Kasdi Merbah Ouargla University, detailing exercises related to linked lists in C programming. It includes tasks such as swapping nodes, finding common elements, and implementing various linked list operations. Additionally, it covers exercises on circular linked lists and doubly linked lists, emphasizing practical programming skills for computer engineering students.

Uploaded by

htm9958
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)
28 views2 pages

TD 4 Linked List

The document outlines a tutorial module for Algorithms and Data Structures at Kasdi Merbah Ouargla University, detailing exercises related to linked lists in C programming. It includes tasks such as swapping nodes, finding common elements, and implementing various linked list operations. Additionally, it covers exercises on circular linked lists and doubly linked lists, emphasizing practical programming skills for computer engineering students.

Uploaded by

htm9958
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

Kasdi Merbah Ouargla University

Faculty of New technologies and information and communication


Computer Science and Information Technology Department

Module: ADS2 Algorithms and Data Structure 2


Instructors: BELHADJ Mourad, MEISSA Marwa & KORICHI Aicha
Academic year: 2024/2025
Class: ING1 Computer engineering
Type: Tutorial

TD 04: Linked lists

Exercise 1 4. Swap two nodes without swapping values.


Input: 10->25->30->15->20->35, x = 25, y =
Write a C program that performs the following tasks: 20
Output: 10->20->30->15->25->35
1. Declare a struct Node with an integer data and
a pointer to the next node. 5. Swap adjacent nodes in pairs.
Input: 10->25->30->15->20->35
2. Create a linked list with 10 nodes, assigning Output: 25->10->15->30->35->20
values from 1 to 10.
6. Find the common elements of two linked lists.
3. Print the linked list. Input:
List 1: 5->10->15->20->25->30
4. Insert a new node with value 50 at the end of List 2: 3->7->10->14->15->25
the list. Output: 10->15->25

5. Delete the node containing the value 5. 7. Find the merging point of two linked lists.
Input:
6. Implement a function to search for a give value List 1: 1->3->5->7->9->11->15->17
V in the list. List 2: 2->4->6->15->17
Output: The merging point is 15.
7. Update the node containing 3 by changing its
value to 77. 8. Reverse a linked list in groups of k nodes.
Input: 10->20->30->40->50->60->70, k = 3
8. Print the list after each operation. Output: 30->20->10->60->50->40->70

9. Access the nth item in the list 9. Merge two sorted linked lists into a single sorted
list.
10. Implement a function to calculate and return Input:
the sum of all node values. List 1: 1->5->9->14->20
List 2: 2->6->10->15->25
Output: 1->2->5->6->9->10->14->15->20-
Exercise 2 >25
Implement the following routines for a singly linked
list: Exercise 3
1. Find the middle node(s) of a linked list. 1. Implement a linked list that stores the following
sequence of numbers:
2. Check if a linked list is a palindrome.
3→8→1→4
3. Remove duplicate elements from both sorted
and unsorted linked lists. (Head → Tail)
2. Modify your implementation to make the list 3. Calculate and display the general average of the
circular so that the last node points back to section by calling the Moy_section(L) func-
the first node. tion, which computes and returns the overall
average of all students.
3. Insert the value 5 after the node containing 8 .
4. Display the list of admitted students using the
4. Delete the node containing 1.
display_admitted(L) procedure. This pro-
5. Traverse the circular linked list starting from cedure should print the details of students who
the head and print the elements. meet the admission criteria.

3 8 1 4 Exercise 6
A web browser stores its history using a doubly
linked list, where each visited webpage is a node
containing:

• The URL of the webpage.


• A pointer to the previous webpage (back-
ward navigation).
Exercise 4 • A pointer to the next webpage (forward
Given a linked list of size N , perform the following navigation).
operations:
1. Create a new linked list L2 that contains only
Back URL Forward
the even elements of the given list.
2. Create another linked list L3 that contains only
the odd elements of the given list. Given the following browsing sequence:

3. Implement a recursive function that computes Google ↔ YouTube ↔ Wikipedia ↔ GitHub


the sum of all elements greater than 10 in a (Google is the first page visited, and GitHub is the
given linked list. latest).
4. Print the maximum number in L2 (even num- 1. Implement the following operations on the dou-
bers). bly linked list:
5. Print the minimum number of the elements in • Back Button: Move from "GitHub" to
L3 (odd numbers). "Wikipedia".
• Forward Button: Move back to
Exercise 5 "GitHub".
Write a C program that performs the following tasks: • New Visit: If the user visits "Stack Over-
flow" from "Wikipedia", update the linked
1. Create a list (L1) containing information about list structure.
first-year computer science students. Each stu-
dent entry should include their ID, name, and 2. Explain the advantage of using a doubly
average grade. The program should prompt the linked list instead of a singly linked list in
user to enter the number of students and their this scenario.
respective details.
2. Sort the list in descending order based on stu- Remark: Exercises 5 and 6 are assigned as
dents’ averages. This should be done by calling homework and should be completed individ-
the Order(L) procedure, which organizes the ually.
list in decreasing order.

You might also like