×
ALL THE HUSTLE, LATE NIGHTS, MISSED PARTIES, EARLY MORNINGS WILL BE WORTH IT.

# Lab Manuals for Data Structure using C - DS By yashika pandey

• Data Structure using C - DS
• Practical
• Dr. A.P.J. Abdul Kalam Technical University - AKTU
• Computer Science Engineering
• 63 Views
Yashika Pandey
0 User(s)

#### Text from page-1

Program: 11 Write A Program In C To Implement Double Ended Queue, Insertion & delection From Front & rear operation #include<stdio.h> #include<stdlib.h> #include<conio.h> #define SIZE 100 int queue[SIZE]; int F = -1; int R = -1; void insert_r(int x) { if(F == (R+1)%SIZE) { printf("\nQueue Overflow"); } else if(R == -1) { F = 0; R = 0; queue[R] = x; } else { R = (R+1) %SIZE; queue[R] = x; } } void insert_f(int x) { if(F == (R+1)%SIZE) { printf("\nQueue Overflow"); } else if(R == -1) { F = 0; R = 0; queue[R] = x; } else { F = (F+SIZE-1) %SIZE;

#### Text from page-2

queue[F] = x; }}} int delete_r() { int x; if(F == -1) { printf("\nQueue Underflow"); } else if(F == R) { x = queue[F]; F = -1; R = -1; } else { x = queue[R]; R = (R+SIZE-1)%SIZE; } return x; } int delete_f() { int x; if(F == -1) { printf("\nQueue Underflow"); } else if(F == R) { x = queue[F]; F = -1; R = -1; } else { x = queue[F]; F = (F+1)%SIZE; } return x; } void main() { char choice;

#### Text from page-3

int x; while(1) { system("cls"); printf("1: Insert From Front\n"); printf("2: Insert From Rear\n"); printf("3: Delete From Front\n"); printf("4: Delete From Rear\n"); printf("5: Exit Program\n"); printf("Enter Your Choice:"); choice = getche(); switch(choice) { case '1': printf("\nEnter Integer Data :"); scanf("%d",&x); insert_f(x); break; case '2': printf("\nEnter Integer Data :"); scanf("%d",&x); insert_r(x); break; case '3': printf("\nDeleted Data From Front End: %d",delete_f()); break; case '4': printf("\nDeleted Data From Back End: %d",delete_r()); break; case '5': exit(0); break; }system("pause"); } Output:

#### Text from page-4

Program: 12 Wap to insert & delete element in Circular linked list #include <stdio.h> #define SIZE 5 int items[SIZE]; int front = -1, rear =-1; int isFull() { if( (front == rear + 1) || (front == 0 && rear == SIZE-1)) return 1; return 0; } int isEmpty() { if(front == -1) return 1; return 0; } void enQueue(int element) { if(isFull()) printf("\n Queue is full!! \n"); else { if(front == -1) front = 0; rear = (rear + 1) % SIZE; items[rear] = element; printf("\n Inserted -> %d", element); } } int deQueue() { int element; front = -1; else { front = (front + 1) % SIZE; }} void display() { int i; if(isEmpty()) printf(" \n Empty Queue\n"); else { printf("\n Front -> %d ",front); printf("\n Items -> "); for( i = front; i!=rear; i=(i+1)%SIZE) { printf("%d ",items[i]); } printf("%d ",items[i]); printf("\n Rear -> %d \n",rear);