0% found this document useful (0 votes)
99 views

DATA Structure Lab Assignment

The document is a certificate from Centurion University certifying that Mr./Ms. Kishan Kumar, with registration number 190101120092, of the 5th semester B.Tech program, has completed experiments in the Computer Science laboratory. It includes an index listing the name, date, page number, and signature for 8 experiments conducted, including on stacks, queues, linked lists, binary search trees, and different sorting algorithms.

Uploaded by

KISHAN KUMAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

DATA Structure Lab Assignment

The document is a certificate from Centurion University certifying that Mr./Ms. Kishan Kumar, with registration number 190101120092, of the 5th semester B.Tech program, has completed experiments in the Computer Science laboratory. It includes an index listing the name, date, page number, and signature for 8 experiments conducted, including on stacks, queues, linked lists, binary search trees, and different sorting algorithms.

Uploaded by

KISHAN KUMAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

CENTURION UNIVERSITY OF TECHNOLOGY AND MANAGEMENT

SCHOOL OF ENGINEERING & TECHNOLOGY, PARALAKHEMUNDI

DEPARTMENT OF Computer science

CERTIFICATE

This is to certify that

Mr/ms. KISHAN KUMAR .

With Registration no. 190101120092 .

Of B.Tech 5th . Semester has conducted .

Experiments in Laboratory

Faculty in -Charge Head of the Department

1
INDEX
Exp.No Name of the Experiment Date Page.No Signature Remarks

1. Stack operations

2. Queue

3. Linked List
4. Binary Search
Tree
5. Linear Search
6. Binary Search

7. Bubble_Short
8. Selection_Sho
rt

2
1. Stack operations:
#include <stdio.h>

#include<conio.h>

#include<stdlib.h>

#define maxsize 5

int stack [maxsize];

int top = -1;

void push(){

int ele;

if (top == maxsize-1)

printf("stack is over flow\n");

else{

printf("Enter the element to the push :");

scanf("%d",&ele);

top = top + 1;

stack[top]= ele;

void pop(){

if (top== -1)

printf("Stack is underflow\n");

else{

printf("the element deleted is:%d\n", stack[top]);

top = top -1;

3
}

void peek(){

if (top == -1)

printf("stack is underflow\n");

else{

printf("top most element is : %d\n",stack[top]);

void display(){

int i;

if (top== -1)

printf("stack is empty\n");

else{

for ( i = 0; i <=0; i++){

printf("%3d",stack[i]);

void main(){

int choice;

do

printf("\n1.push\n");

printf("2.pop\n");

printf("3.peek\n");

printf("4.display\n");

printf("5.exit\n");

4
printf("enter your choise:");

scanf("%d",&choice);

switch (choice)

case 1:push(); break;

case 2:pop(); break;

case 3:peek(); break;

case 4:display(); break;

case 5:exit(0);

} while (choice<=5);

OUTPUT:

2. Queue :-
Code:- #include <iostream>
5
using namespace std;

int queue[100], n = 100, front = - 1, rear = - 1;

void Insert() {

int val;

if (rear == n - 1)

cout<<"Queue Overflow"<<endl;

else {

if (front == - 1)

front = 0;

cout<<"Insert the element in queue : "<<endl;

cin>>val;

rear++;

queue[rear] = val;

void Delete() {

if (front == - 1 || front > rear) {

cout<<"Queue Underflow ";

return ;

} else {

cout<<"Element deleted from queue is : "<< queue[front] <<endl;

front++;;

void Display() {

if (front == - 1)

cout<<"Queue is empty"<<endl;

else {

cout<<"Queue elements are : ";

for (int i = front; i <= rear; i++)

cout<<queue[i]<<" ";

cout<<endl;

6
}

int main() {

int ch;

cout<<"1) Insert element to queue"<<endl;

cout<<"2) Delete element from queue"<<endl;

cout<<"3) Display all the elements of queue"<<endl;

cout<<"4) Exit"<<endl;

do {

cout<<"Enter your choice : "<<endl;

cin>>ch;

switch (ch) {

case 1: Insert();

break;

case 2: Delete();

break;

case 3: Display();

break;

case 4: cout<<"Exit"<<endl;

break;

default: cout<<"Invalid choice"<<endl;

} while(ch!=4);

return 0;

O/P:

7
3. Linked List:-
Code:- #include <stdio.h>
#include<conio.h>

#include<stdlib.h>

struct node{

int data;

struct node*next;

*p,*tmp,*tmp1;

void insert_end(int);

void insert_beg(int);

void i_delete(int);

void delete_beg();

void delete_end();

void display();

void main(){

int val,n;

p=NULL;

do

printf("********menu*********");

8
printf("\n1.INSERT AT END");

printf("\n2.Insert at big");

printf("\n3.Delete a partucular ele");

printf("\n4.Delete from big ");

printf("\n5.Delete from end");

printf("\n6.Display");

printf("\n7.exit");

printf("\nenter you choice:");

scanf("%d",&n);

switch(n){

case 1:

printf("\nenter the value");

scanf("%d",&val);

insert_end(val);

break;

case 2:

printf("\nenter the value");

scanf("%d",&val);

insert_beg(val);

break;

case 3:

printf("\nenter the value");

scanf("%d",&val);

i_delete(val);

break;

case 4:

delete_beg();

break;

case 5:

delete_end();

break;

9
case 6:

display();

break;

case 7:

exit(0);

break;

default:

printf("\n Wrong Choice!");

break;

printf("\n do u want to cont....");

while('y'==getch());

void insert_end(int ele){

tmp= p;

tmp1= (struct node*)malloc(sizeof(struct node));

tmp1->data=ele;

tmp1->next=NULL;

if(p==NULL)

p=tmp1;

else

while(tmp->next!=NULL)

tmp=tmp->next;

tmp->next=tmp1;

void insert_beg(int ele){

tmp=p;

tmp1=(struct node*)malloc(sizeof(struct node));

10
tmp1->data=ele;

tmp1->next=p;

p=tmp1;

void i_delete(int ele){

tmp=p;

struct node *pre=tmp;

while(tmp!=NULL){

if(tmp->data==ele){

if(tmp==p){

p=tmp->next;

free(tmp);

return;

else{

pre->next=tmp->next;

free(tmp);

return;

else{

pre=tmp;

tmp=tmp->next;

printf("\n no match found!!");

void delete_beg(){

tmp=p;

if(p==NULL)

printf("\n no element to be deleted!!");

11
else{

printf("\nelement deleted-%d",p->data);

p=p->next;

void delete_end(){

tmp=p;

struct node* pre;

if(p==NULL)

printf("\n no element to be deleted!!");

else if(p->next==NULL){

printf("\n element deleted-%d",p->data);

p=NULL;

else{

while(tmp->next!=NULL){

pre=tmp;

tmp=tmp->next;

pre->next=NULL;

printf("\n element deleted-%d",tmp->data);

void display(){

tmp=p;

while(tmp!=NULL){

printf("\n%d",tmp->data);

tmp=tmp->next;

O/P:

12
4.BinarySearch Tree:-
Code: #include <stdio.h>
#include<conio.h>

#include<stdlib.h>

struct node{

int data;

struct node*next;

*p,*tmp,*tmp1;

void insert_end(int);

void insert_beg(int);

void i_delete(int);

void delete_beg();

void delete_end();

void display();

void main(){

int val,n;

p=NULL;

do

printf("********menu*********");

printf("\n1.INSERT AT END");

printf("\n2.Insert at big");

13
printf("\n3.Delete a partucular ele");

printf("\n4.Delete from big ");

printf("\n5.Delete from end");

printf("\n6.Display");

printf("\n7.exit");

printf("\nenter you choice:");

scanf("%d",&n);

switch(n){

case 1:

printf("\nenter the value");

scanf("%d",&val);

insert_end(val);

break;

case 2:

printf("\nenter the value");

scanf("%d",&val);

insert_beg(val);

break;

case 3:

printf("\nenter the value");

scanf("%d",&val);

i_delete(val);

break;

case 4:

delete_beg();

break;

case 5:

delete_end();

break;

case 6:

display();

14
break;

case 7:

exit(0);

break;

default:

printf("\n Wrong Choice!");

break;

printf("\n do u want to cont....");

while('y'==getch());

void insert_end(int ele){

tmp= p;

tmp1= (struct node*)malloc(sizeof(struct node));

tmp1->data=ele;

tmp1->next=NULL;

if(p==NULL)

p=tmp1;

else

while(tmp->next!=NULL)

tmp=tmp->next;

tmp->next=tmp1;

void insert_beg(int ele){

tmp=p;

tmp1=(struct node*)malloc(sizeof(struct node));

tmp1->data=ele;

tmp1->next=p;

15
p=tmp1;

void i_delete(int ele){

tmp=p;

struct node *pre=tmp;

while(tmp!=NULL){

if(tmp->data==ele){

if(tmp==p){

p=tmp->next;

free(tmp);

return;

else{

pre->next=tmp->next;

free(tmp);

return;

else{

pre=tmp;

tmp=tmp->next;

printf("\n no match found!!");

void delete_beg(){

tmp=p;

if(p==NULL)

printf("\n no element to be deleted!!");

else{

16
printf("\nelement deleted-%d",p->data);

p=p->next;

void delete_end(){

tmp=p;

struct node* pre;

if(p==NULL)

printf("\n no element to be deleted!!");

else if(p->next==NULL){

printf("\n element deleted-%d",p->data);

p=NULL;

else{

while(tmp->next!=NULL){

pre=tmp;

tmp=tmp->next;

pre->next=NULL;

printf("\n element deleted-%d",tmp->data);

void display(){

tmp=p;

while(tmp!=NULL){

printf("\n%d",tmp->data);

tmp=tmp->next;

O/P:

17
5.Linear Search:
Code:
#include<iostream>

using namespace std;

18
int main()

int arr[100], tot, i, num, arrTemp[50], j=0, chk=0;

cout<<"Enter the Size for Array Size: ";

cin>>tot;

cout<<"Enter "<<tot<<" Array Elements: ";

for(i=0; i<tot; i++)

cin>>arr[i];

cout<<"\nEnter the Number to Search: ";

cin>>num;

for(i=0; i<tot; i++)

if(arr[i]==num)

arrTemp[j] = i;

j++;

chk++;

if(chk>0)

cout<<"\nNumber Found at Index No. ";

tot = chk;

for(i=0; i<tot; i++)

cout<<arrTemp[i]<<" ";

else

cout<<"\nNumber doesn't Found!";

cout<<endl;

return 0;

19
O/P:

6. Binary Search:
Code:
#include <stdio.h>

int bs(int a[],int beg,int end,int key){

int loc=0;

if(end >= beg)

int mid=(beg+end)/2;

if(key>a[mid]){

beg=mid+1;

return bs(a,beg,end,key);

else if(key==a[mid]){

loc=mid+1;

return loc;

else if(key<a[mid]){

end=mid-1;

return bs(a,beg,end,key);

20
}

else

return -1;

int main()

int n,a[20],i,key,loc=-1;

printf("Enter range:\n");

scanf("%d",&n);

printf("Enter elements:\n");

for(i=0;i<n;i++){

scanf("%d",&a[i]);

printf("Key:\n");

scanf("%d",&key);

loc=bs(a,0,n,key);

if(loc!=-1){

printf("Element found at loc %d",loc);

else{

printf("Element not found !!");

return 0;

21
O/P:

7. Bubble_Short:
Code:- #include <stdio.h>

int main()

int array[100], n, c, d, swap;

printf("Enter number of elements\n");

scanf("%d", &n);

printf("Enter %d integers\n", n);

for (c = 0; c < n; c++)

scanf("%d", &array[c]);

22
for (c = 0 ; c < n - 1; c++)

for (d = 0 ; d < n - c - 1; d++)

if (array[d] > array[d+1]) /* For decreasing order use '<' instead of '>' */

swap = array[d];

array[d] = array[d+1];

array[d+1] = swap;

printf("Sorted list in ascending order:\n");

for (c = 0; c < n; c++)

printf("%d\n", array[c]);

return 0;

O/P:

23
8.Selection_Short:
Code:
#include<iostream>

using namespace std;

void swapping(int &a, int &b) {

int temp;

temp = a;

a = b;

b = temp;

void display(int *array, int size) {

for(int i = 0; i<size; i++)

cout << array[i] << " ";

cout << endl;

void selectionSort(int *array, int size) {

int i, j, imin;

for(i = 0; i<size-1; i++) {

imin = i;

for(j = i+1; j<size; j++)

if(array[j] < array[imin])

imin = j;

swap(array[i], array[imin]);

int main() {

int n;

cout << "Enter the number of elements: ";

cin >> n;

24
int arr[n];

cout << "Enter elements:" << endl;

for(int i = 0; i<n; i++) {

cin >> arr[i];

cout << "Array before Sorting: ";

display(arr, n);

selectionSort(arr, n);

cout << "Array after Sorting: ";

display(arr, n);

}}

O/P:

25

You might also like