0% found this document useful (0 votes)
6 views4 pages

DSA 10 Marks Answers Part1

The document discusses the implementation and applications of stacks, queues, and linked lists in data structures, highlighting their operations and providing example C code. It covers stack operations such as PUSH, POP, and PEEK, and applications like expression evaluation and recursion. Additionally, it explains queue types (simple, circular, and deque) and linked list operations, along with algorithms for infix to postfix conversion and postfix expression evaluation.
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)
6 views4 pages

DSA 10 Marks Answers Part1

The document discusses the implementation and applications of stacks, queues, and linked lists in data structures, highlighting their operations and providing example C code. It covers stack operations such as PUSH, POP, and PEEK, and applications like expression evaluation and recursion. Additionally, it explains queue types (simple, circular, and deque) and linked list operations, along with algorithms for infix to postfix conversion and postfix expression evaluation.
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/ 4

Stack Implementation and Applications

A stack is a linear data structure that follows the Last In First Out (LIFO) principle. The element

inserted last is the first to be removed.

Operations:

- PUSH: Insert an element

- POP: Remove top element

- PEEK: View top element

- DISPLAY: Show stack contents

Example C Program:

#include <stdio.h>

#define SIZE 100

int stack[SIZE];

int top = -1;

void push(int value) { ... }

void pop() { ... }

void peek() { ... }

void display() { ... }

int main() { ... }

Applications:

- Expression evaluation

- Recursion

- Undo features

- Backtracking algorithms
Queue Implementation (Simple, Circular, Dqueue)

Queues are linear data structures that follow First In First Out (FIFO) principle.

Basic Queue using array:

#include <stdio.h>

#define SIZE 5

int queue[SIZE];

int front = -1, rear = -1;

void enqueue(int value) { ... }

void dequeue() { ... }

void display() { ... }

Circular Queue and Dqueue allow more flexible insert/delete operations.

Linked List Operations (Insert, Delete, Display)

Linked list is a linear data structure where each node contains data and a pointer to the next node.

Example:

struct Node {

int data;

struct Node* next;

};

Operations:

- Insert at beginning
- Delete from beginning

- Display

Functions:

void insert(int value) { ... }

void delete() { ... }

void display() { ... }

Infix to Postfix Conversion

Algorithm:

1. Scan infix expression from left to right

2. Use stack to store operators

3. Output operands immediately

4. Pop stack for operators according to precedence

Example C code:

#include <stdio.h>

char stack[SIZE];

int precedence(char op) { ... }

void infixToPostfix(char* infix) { ... }

Evaluation of Postfix Expression

Algorithm:

1. Scan expression from left to right

2. Push operands to stack


3. Pop and evaluate when operator is found

Example C code:

int evaluatePostfix(char* exp) {

for each character:

if operand -> push

if operator -> pop two, apply, push result

You might also like