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

Stack Data Structure Tasks in C

The document outlines five tasks related to implementing stack data structures in C. Task 1 involves creating a dynamic array stack for a music playlist feature, while Task 2 focuses on implementing two stacks within a single array. Tasks 3 to 5 cover reversing a list, simulating an undo feature, and checking for palindromes using stacks, demonstrating various applications of the LIFO principle.

Uploaded by

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

Stack Data Structure Tasks in C

The document outlines five tasks related to implementing stack data structures in C. Task 1 involves creating a dynamic array stack for a music playlist feature, while Task 2 focuses on implementing two stacks within a single array. Tasks 3 to 5 cover reversing a list, simulating an undo feature, and checking for palindromes using stacks, demonstrating various applications of the LIFO principle.

Uploaded by

rhulsung
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Task 1:

Imagine you are building a simple playlist feature for a music application. This feature is
responsible for handling the “Now Playing” queue where users can:

 Add a new song to the top of the queue (just like choosing "Play Next").
 Remove the currently playing song (when it finishes).
 View which song is currently playing.
 See the current list of songs in order of playback.

Implement a Stack using a Dynamic Array (malloc/realloc): The goal is to learn


how to use dynamic memory allocation in C (using malloc, calloc etc) to create a stack
that can grow in size as needed when elements are pushed.

In static arrays, the size is fixed. But with dynamic memory, we can allocate memory at
runtime and resize it if the stack gets full.

Task 2:

Multiple Stacks in a Single Array: The objective of this task is to implement two stacks in
a single array such that:

 The two stacks grow toward each other from opposite ends of the array.
 Memory is efficiently utilized, and no space is wasted if one stack is smaller than the
other.
 Overflow occurs only when the entire array is full — not when a single stack reaches
the middle.

This approach helps you understand how to optimize space when using a single container
(array) for multiple logical stacks.

Task-3

Reverse a List using Stack: The goal is to understand how to use the stack data
structure to reverse the order of elements in a list. This task reinforces the LIFO (Last In,
First Out) property of stacks.

When you push elements of a list into a stack and then pop them one by one, you retrieve
them in reverse order.

Task-4
Undo Feature Simulation using Stack: The aim of this task is to demonstrate a real-
world application of stacks by simulating an Undo feature, similar to what we use in text
editors.

 Every time a user types a word or character, it is pushed onto a stack.


 When the user presses Undo, the last action (i.e., the top of the stack) is popped.
 This reflects the LIFO (Last In, First Out) principle of stack data structure.

Task-5

Palindrome Check using Stack: This task aims to use a stack to determine if a string is a
palindrome, i.e., it reads the same forward and backward (e.g., madam, racecar).

By pushing characters onto a stack and then popping them out, we get the reverse of the
string. Comparing this reversed string with the original one helps us verify whether the string
is a palindrome.

You might also like