Lab-2
Lab-2
Lab-2
Tasks:
1. Create a Node class to represent each element in the linked list.
2. Implement functions to add a node at the beginning, end, and a specified
position.
3. Implement functions to delete a node by value, by position, and delete all nodes.
4. Write a function to reverse the linked list.
1
Department of Computer Science
Data Structure and Algorithm (DSA) Lab 02:
Lab Task 2: Implementing a Stack using Linked List
Tasks:
1. Implement a stack using a singly linked list.
2. Implement push (to add an element), pop (to remove the top element), and peek (to
view the top element) operations.
3. Add an isEmpty function to check if the stack is empty.
4. Add a function to display all elements in the stack.
Task
• Take a string of parentheses (like "( [ { } ] )") as input.
• Implement a stack to check if the parentheses are balanced.
• For instance, for an input of "({[]})", the output should confirm balanced
parentheses.
• Provide informative output on whether the input string is balanced or not.
Task
• Create a Node class and a CircularLinkedList class.
• Implement functions to add nodes at the beginning and end of the list.
• Implement a function to traverse the list and print all elements, showing the
circular nature of the list.
• Write a method to delete a node from the list. 2
Department of Computer Science
Data Structure and Algorithm (DSA) Lab 02:
Lab Task 5: Implement a Stack with Dynamic Size
Tasks:
1. Implement a stack using an array with an initial size, say 10.
2. If the stack reaches its capacity, double the array size to accommodate more
elements.
3. Implement push, pop, and peek methods along with the resizing logic.
3
Department of Computer Science
Data Structure and Algorithm (DSA) Lab 02: