0% found this document useful (0 votes)
9 views13 pages

DSimput 1

The document covers fundamental concepts in data structures, including the differences between arrays and linked lists, the conversion of infix notation to postfix, and algorithms for evaluating postfix expressions. It defines Abstract Data Types (ADTs) and details stack and queue operations using both arrays and linked lists. Additionally, it explains the types of linked lists and provides C program examples for implementing stack and queue operations.

Uploaded by

Vivek V
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)
9 views13 pages

DSimput 1

The document covers fundamental concepts in data structures, including the differences between arrays and linked lists, the conversion of infix notation to postfix, and algorithms for evaluating postfix expressions. It defines Abstract Data Types (ADTs) and details stack and queue operations using both arrays and linked lists. Additionally, it explains the types of linked lists and provides C program examples for implementing stack and queue operations.

Uploaded by

Vivek V
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/ 13

UNIT - I

1.Write the differences between Array and linked list?


2.Convert the following infix notation to post fix a+b*c?
3.Write an algorithm to evaluate postfix expression

Algorithm to evaluate postfix exp


Algorithm : Evaluation of Postfix Expression
— Create an empty stack and start scanning the postfix expression from
left to right.
— If the element is an operand, push it into the stack.
— If the element is an operator O, pop twice and get A and B
respectively. Calculate BOA and push it back to the stack.
— When the expression is ended, the value in the stack is the final
answer.

Evaluation of a postfix expression using a stack is explained in below


example:
4.Define ADT and write stack ADT?

Abstract Data Types


The abstract datatype is special kind of datatype, whose behavior is defined by a set of values and set of operations.
The keyword “Abstract” is used declare abstract datatypes. We can use these datatypes, to perform different
operations. But how those operations are working that is totally hidden from the user. Some examples of ADT are
— Stack
— Queue
— List etc.
ADT Stack:

Elements:
A Stack contains elements of the same type arranged in sequential order. All operations take place at a single end
that is top of the stack.
Operations:
— push() – Insert an element at one end of the stack called top.
— pop() – Remove and return the element at the top of the stack, if it is not empty.
— peek() – Return the element at the top of the stack without removing it, if the stack is not empty.
— size() – Return the number of elements in the stack.
— isEmpty() – Return true if the stack is empty, otherwise return false.
— isFull() – Return true if the stack is full, otherwise return false.
5.what is linked list and explain different types of Linked List with examples?

Linked list is a collection of elements called nodes.Each node contains two parts. They are data
part and link part.

There are three common types of Linked List.

1. Singly Linked List


2. Doubly Linked List
3. Circular Linked List
Singly Linked List
It is the most common. Each node has data and a pointer to the next node.
Ex:
Doubly Linked List
We add a pointer to the previous node in a doubly-linked list. Thus, we can go in either direction: forward or backward

Circular Linked list


A circular linked list is a variation of a linked list in which the last element is linked to the first element. This forms a
circular loop.
7.Write a C program to perform stack operations using Arrays?

Push Algorithm: POP Algorithm:


void push(int data) int pop()
{ {
if(top!=Maxsize)) if(top !=-1)
{ {
top = top + 1; n=stack[top];
stack[top] = data; top--;
} }
else else
{ {
printf("Could not insert data, Stack is full.\n"); printf(“stack Underflow…\n”);
} }
} return n;
}
8.Write a C program to perform Queue operations using Arrays?
Display Algorithm:
void display() void insert()
{ {
if(top>=0)
int item;
{
printf("\n The elements in STACK if(rear == MAX - 1)
\n"); printf("Queue Overflow n");
for(i=top; i>=0; i--) else
printf("\n%d",stack[i]); {
printf("\n Press Next Choice"); if(front== - 1)
} front = 0;
else printf("Inset the element in queue :
{ ");
printf("\n The STACK is empty");
scanf("%d", &item);
}
} rear = rear + 1;
queue_array[rear] = item;
}
}
void delete() void display()
{ {
if(front == - 1 || front > rear) int i;
{ if(front == - 1)
printf("Queue Underflow n"); printf("Queue is empty n");
return; else
} {
else printf("Queue is : n");
{ for(i = front; i <= rear; i++)
printf("Element deleted from queue is : %dn", printf("%d ", queue_array[i]);
queue_array[front]); printf("n");
front = front + 1; }
} }
}
9.Write a C program to perform stack operations using linked list?

Stack operations Using Linked list Pop() Algorithm:


int pop()
Push() Algorithm: {
void push(int data) if(top !=-1)
{ {
if(top!=Maxsize)) n=stack[top];
{ top--;
top = top + 1; }
stack[top] = data; else
} {
else printf(“stack Underflow…\n”);
{ }
printf("Could not insert data, Stack is full.\n"); return n;
} }
}
Display Algorithm: 10.Write a C program to performQueue operations using linked list?
void display()
{ Queue operations Using Linked List Representation
node1 *temp;
if (top== NULL) Insertion () Algorithm
{ struct node
printf("Stack is empty"); {
} int data;
else struct node *next;
{ };
printf("the elements in the stack are\n"); typedef struct node node1;
temp = top; node1 *front=NULL,*rear= NULL;
while (temp!= NULL) Insertion Operation
{ Void insert()
printf("%d ", temp->data); {
temp = temp->next; int n;
} node1 *temp;
printf("NULL\n"); temp = (node1*)malloc(sizeof(node1));
} print("Enter the element to be insert ");
} scanf("%d",&n);
temp->data=n;
temp->next=NULL;
if(front==NULL)
{ front= temp; Deletion() operation Algorithm:
rear= temp; void del()
} {
else{ int n;
rear = front; node1 *temp;
while(rear->next!=NULL){ if(front==NULL)
rear=rear->next; printf("Queue is empty\n");
} else
rear->next=temp; {
rear=temp;
} temp =front;
} front =front->next;
printf("The deleted element is %d\n",temp->data);
free(temp);
}
}
Display() operation algorithm:
void display()
{
node1 * temp;

if (front == NULL) {
print("Queue is empty");
}
else
{
while (temp != rear)
{
printf("%d ", temp->data);
temp = temp->next;
}
}
}

You might also like