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

Linked List Stack Implementation Guide

The document outlines three exercises related to linked list operations in CPP programming. Exercise 1 involves implementing a stack using linked lists with push and pop operations. Exercises 2 and 3 focus on reversing linked lists in groups and eliminating duplicates, respectively.

Uploaded by

abdelkadero13579
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)
3 views2 pages

Linked List Stack Implementation Guide

The document outlines three exercises related to linked list operations in CPP programming. Exercise 1 involves implementing a stack using linked lists with push and pop operations. Exercises 2 and 3 focus on reversing linked lists in groups and eliminating duplicates, respectively.

Uploaded by

abdelkadero13579
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

CPP Programming

Noureddine Hamid - Redone Mahjoubi


TP 00

Exercice 1:
Implement stack using linked list.
To implement a stack using a linked list, basically we need to implement the
push() and pop() operations of a stack using linked list.

Input:
1,3,5,8,4,0

We push the numbers into the stack and whenever it executes a pop() oper-
ation, the number is popped out from the stack.

Algorithm:

To implement the push() operation:


- If the Linked list is empty then create a node and point it as head of that
Linked List.
- If the Linked List is not empty then create a node with the input number to

1
be pushed and make it head of the Linked List.

To implement The pop() operation:


- If the Linked List is already empty then do nothing. Output that empty stack.
- If the Linked List is not empty then delete the node from head.

Exercice 2:
Reverse the linked List in groups of given size.
Given a linked list of size N. The task is to reverse every k nodes in the linked list.

Example:

1→2→3→4→5→6→7→8
The value of k is 2
The reversed linked list: 2 → 1 → 4 → 3 → 6 → 5 → 8 → 7

Exercice 3:
Eliminate duplicates from the linked list.

Example:

1→2→3→3→4→5→6→7→8
The new linked list:
1→2→3→4→5→6→7→8

You might also like