Kum DS Lab
Kum DS Lab
PROGRAM 4
WAP of array implement of SPARSE MATRIX.
#include <stdio.h>
#include <conio.h>
#define MAX 20
struct triplet {
int row;
int col;
int element;
} spmatrix[MAX];
void main () {
int n, i, j, row, col;
int k = 0;
getch();
}
Experiment No. ………………… Date……………….
OUTPUT: -
Experiment No. ………………… Date……………….
PROGRAM 5
WAP in C to perform push and pop operation on an element in stack.
#include <stdio.h>
#include <conio.h>
#define MAX 50
void main () {
printf("Programmed by KUMKUM KUMARI\n");
create ();
printf("\nStack is:\n");
traverse ();
push ();
printf("After pushing an element, the stack is:\n");
traverse ();
pop ();
printf("After popping an element, the stack is:\n");
traverse ();
getch();
}
void create () {
char ch;
do {
if (top == MAX) {
printf("Stack is full (overflow).\n");
return;
}
top++;
printf("Input element: ");
scanf("%d", &stack[top]);
printf("Press <y> to add more elements, any other key to stop: ");
ch = getch();
} while (ch == 'y');
}
Experiment No. ………………… Date……………….
void traverse () {
if (top == 0) {
printf("Stack is empty.\n");
return;
}
for (int i = top; i > 0; --i)
printf("%d\n", stack[i]);
}
void push () {
int m;
if (top == MAX) {
printf("Stack is full (overflow).\n");
return;
}
printf("Input new element to insert: ");
scanf("%d", &m);
top++;
stack[top] = m;
}
void pop() {
if (top == 0) {
printf("Stack is empty (underflow).\n");
return;
}
printf("Popped element: %d\n", stack[top]);
stack[top] = 0;
top--;
}
OUTPUT: -
Experiment No. ………………… Date……………….
PROGRAM 6
void main() {
int n;
char A = 'A', B = 'B', C = 'C';
void hanoi(int, char, char, char);
OUTPUT: -
Experiment No. ………………… Date……………….
PROGRAM 7: -
WAP in C to implement QUEUE using array.
#include<stdio.h>
#include<conio.h>
#define MAX 100
void main() {
void create();
void traverse();
void insert();
void delet();
void create() {
char ch;
front = 1;
do {
rear++;
printf("\nInput element in queue:\n");
scanf("%d", &q[rear]);
printf("Press <Y/N> for more elements");
ch = getch();
} while (ch == 'Y');
}
void traverse() {
int i;
printf("\nElements in the queue are:\n");
for (i = front; i <= rear; ++i)
printf("%d\n", q[i]);
}
Experiment No. ………………… Date……………….
void insert() {
int m;
if (rear == MAX) {
printf("Queue is overflow\n");
return;
}
printf("\nInput new element to insert\n");
scanf("%d", &m);
rear++;
q[rear] = m;
}
void delet() {
if (front == 0) {
printf("Queue is underflow\n");
return;
}
if (front == rear) {
q[front] = '\0';
front = rear = 0;
} else {
q[front] = '\0';
front++;
}
}
OUTPUT: -