Lab-2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Data Structure and Algorithm (JAVA)

Semester V (Fall 2022)


Course Instructor: Mr. Muhammad Saleem

Deadline: 15th of November, 2024


LAB 02
OBJECTIVE(S):

1. Practice implementing a singly linked list from scratch.


2. Understand and implement a circular linked list.
3. Understand stack operations using a linked list as the underlying data structure.
4. Use stack operations to solve a real-world problem.
5. Create a stack that automatically resizes when the stack exceeds its initial capacity.

Lab Task 1: Implementing Singly Linked List

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.

Lab Task 3: Application of Stack – Checking for Balanced Parentheses

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.

Lab Task 4: Circular Linked List Implementation

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:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy