0% found this document useful (1 vote)
223 views

Lab Report of Data Structure Lab Course Code: CSE-206: U N I V E R S I T Y

This lab report summarizes three C programs submitted by MD. FARTHOS ALL AMIN KABBO to their lecturer: 1. A program that checks if a given integer array is sorted in ascending or descending order using a single pass through the array. 2. A program that implements a stack using an array with push and pop operations. 3. A program that implements a queue using an array with insert and delete operations.

Uploaded by

abdul mannan
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 (1 vote)
223 views

Lab Report of Data Structure Lab Course Code: CSE-206: U N I V E R S I T Y

This lab report summarizes three C programs submitted by MD. FARTHOS ALL AMIN KABBO to their lecturer: 1. A program that checks if a given integer array is sorted in ascending or descending order using a single pass through the array. 2. A program that implements a stack using an array with push and pop operations. 3. A program that implements a queue using an array with insert and delete operations.

Uploaded by

abdul mannan
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/ 7

U N I V E R S I T Y

Lab Report of Data Structure Lab


Course Code: CSE-206
Department of Computer Science and Engineering
Date of Submission: 05-06-2020

Submitted By: Submitted To:


MD. FARTHOS ALL AMIN KABBO Md. Abu Syed
Roll No: 23 Lecturer
Reg. No: 108808 Dhaka International
Batch: 51-1st Shift University
Semester : 5th

Signature
1. Write a c program that will check whether a given array
(list of numbers) sorted or not?

1 #include <stdio.h>
2 int main()
3 {
4 int n, s[1000], a = 1, d = 1, i;
5 printf("Enter The Number of array: ");
6 scanf("%d", &n);
7 for (i = 0; i < n; i++)
8 scanf("%d", &s[i]);
9 i = 0;
10 while ((a == 1 || d == 1) && i < n -1)
11 {
12 if (s[i] < s[i+1])
13 d = 0;
14 else if (s[i] > s[i+1])
15 a = 0;
16 i++;
17 }
18 if (a == 1)
19 printf("The array is sorted in ascending
order.\n");
20 else if (d == 1)
21 printf("The array is sorted in descending
order.\n");
22 else
23 printf("The array is not sorted.\n");
24 return 0;
25 }
2. Implement stack with push and pop operation.
1 #include<stdio.h>
2 int stack[100],choice,n,top,x,i;
3 void push(void);
4 void pop(void);
5 void display(void);
6 int main()
7 {
8 top=-1 ;
9 printf("\n Enter the size of STACK[MAX=100]:");
10 scanf("%d",&n);
11 printf("\n\t STACK OPERATIONS USING ARRAY");
12 printf("\n\t--------------------------------");
13 printf("\n\t 1.PUSH\n\t 2.POP\n\t 3.DISPLAY\n\t 4.EXIT");
14 do
15 {
16 printf("\n Enter the Choice:");
17 scanf("%d",&choice);
18 switch(choice)
19 {
20 case 1 :
21 {
22 push();
23 break;
24 }
25 case 2:
26 {
27 pop();
28 break;
29 }
30 case 3:
31 {
32 display();
33 break;
34 }
35 case 4:
36 {
37 printf("\n\t EXIT POINT ");
38 break;
39 }
40 default:
41 {
42 printf ("\n\t Please Enter a Valid
Choice(1/2/3/4)");
43 }
44 }
45 }
46 while(choice!=4);
47 return 0;
48 }
49 void push()
50 {
51 if(top>=n-1 )
52 {
53 printf("\n\tSTACK is over flow");
54
55 }
56 else
57 {
58 printf(" Enter a value to be pushed:");
59 scanf("%d",&x);
60 top++;
61 stack[top]=x;
62 }
63 }
64 void pop()
65 {
66 if(top<=-1 )
67 {
68 printf("\n\t Stack is under flow");
69 }
70 else
71 {
72 printf("\n\t The popped elements is %d",stack[top]);
73 top--;
74 }
75 }
76 void display()
77 {
78 if(top>=0)
79 {
80 printf("\n The elements in STACK \n");
81 for(i=top; i>=0; i--)
82 printf("\n%d",stack[i]);
83 printf("\n Press Next Choice");
84 }
85 else
86 {
87 printf("\n The STACK is empty");
88 }
89 }

3. Implement Queue with insert and delete operation.


1 // C Program to Implement a Queue using an Array
2
3 #include <stdio.h>
4
5 #define MAX 50
6
7 void insert();
8 void delete();
9 void display();
10 int queue_array[MAX];
11 int rear = - 1;
12 int front = - 1;
13 main()
14 {
15 int choice;
16 while (1)
17 {
18 printf("1.Insert element to queue \n");
19 printf("2.Delete element from queue \n");
20 printf("3.Display all elements of queue \n");
21 printf("4.Quit \n");
22 printf("Enter your choice : ");
23 scanf("%d", &choice);
24 switch (choice)
25 {
26 case 1:
27 insert();
28 break;
29 case 2:
30 delete();
31 break;
32 case 3:
33 display();
34 break;
35 case 4:
36 exit(1);
37 default:
38 printf("Wrong choice \n");
39 } /* End of switch */
40 } /* End of while */
41 } /* End of main() */
42
43 void insert()
44 {
45 int add_item;
46 if (rear == MAX - 1)
47 printf("Queue Overflow \n");
48 else
49 {
50 if (front == - 1)
51 /*If queue is initially empty */
52 front = 0;
53 printf("Inset the element in queue : ");
54 scanf("%d", &add_item);
55 rear = rear + 1;
56 queue_array[rear] = add_item;
57 }
58 } /* End of insert() */
59
60 void delete()
61 {
62 if (front == - 1 || front > rear)
63 {
64 printf("Queue Underflow \n");
65 return ;
66 }
67 else
68 {
69 printf("Element deleted from queue is : %d\n",
queue_array[front]);
70 front = front + 1;
71 }
72 } /* End of delete() */
73
74 void display()
75 {
76 int i;
77 if (front == - 1)
78 printf("Queue is empty \n");
79 else
80 {
81 printf("Queue is : \n");
82 for (i = front; i <= rear; i++)
83 printf("%d ", queue_array[i]);
84 printf("\n");
85 }
86 } /* End of display() */

You might also like