Posts

DATA STRUCTURE:ASSIGNMENT NO.7:QUEUE

 PRACTICE PROGRAM: 1) Write a C program to Implement Static implementation of circular queue of integers which  includes operation as: a) Initialize() b) insert() c) delete() d) isempty() e) isfull() f) display()  g) peek()  ANS: #include <stdio.h> #include <conio.h> #define max 10 typedef struct queue {     int item[max];     int front, rear; } QUEUE; void initQueue(QUEUE *q) {     q->front = -1;     q->rear = -1; } int isEmpty(QUEUE *q) {     return (q->front == -1 && q->rear == -1) ? 1 : 0; } int isFull(QUEUE *q) {     return ((q->rear + 1) % max == q->front) ? 1 : 0; } void insert(QUEUE *q, int n) {     if (isFull(q))     {         printf("\n The Queue is full!");     }     else     {         if (isEmpty(q))         {            ...

DATA STRUCTURE:ASSIGNMENT NO.6:STACK

 PRACTICE PROGRAM:- 4) Write a C Program to sort a stack using temporary stack. ANS: #include <stdio.h> #include <conio.h> #define max 100 typedef struct stack {     int top;     int item[max]; } STACK; int isEmpty(STACK *ps) {     if (ps->top == -1)         return 1;     else         return 0; } int isFull(STACK *ps) {     if (ps->top == max - 1)         return 1;     else         return 0; } void push(STACK *ps, int n) {     if (isFull(ps))         printf("\n Stack is full----");     else     {         ps->top++;         ps->item[ps->top] = n;     } } int pop(STACK *ps) {     int x;     if (isEmpty(ps))         printf("\n Stack is Empty---");     else     { ...