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

Data Structure Practical Complet Simran

This document is a practical file for a Bachelor of Computer Applications program at I.G. Govt. College, Tohana, submitted by Simran. It includes various programming exercises related to data structures, such as array manipulations, sorting algorithms, and search algorithms, with source code and outputs provided for each program. The file serves as a comprehensive guide for understanding and implementing fundamental data structure concepts.

Uploaded by

simranranga85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Data Structure Practical Complet Simran

This document is a practical file for a Bachelor of Computer Applications program at I.G. Govt. College, Tohana, submitted by Simran. It includes various programming exercises related to data structures, such as array manipulations, sorting algorithms, and search algorithms, with source code and outputs provided for each program. The file serves as a comprehensive guide for understanding and implementing fundamental data structure concepts.

Uploaded by

simranranga85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

A

Practical File

On

Data Structure

Submitted

For

Bachelor of Computer Applications

At

I.G. Govt. College, Tohana

2025

Submitted To: Submitted By:

Er. Ram Gopal Name: SIMRAN

Roll no: 24028115470022

Class: BCA 2nd Sem

1
Index Page

Sr. No. Name of Program Page No. Signature

UNIT I
Write a program to perform insertion in
1.
array.
Write a program to perform Deletion from
2. array.
Write a program to perform bubble sort on
3. array.
Write a program to perform Selection sort
4.
on array.
Write a program to perform Insertion sort on
5.
array.
Write a program to perform Quick sort on
6.
array.
Write a program to implement Linear Search
7.
in Array.

UNIT II
WAP to use a Linear Array as stack data
8.
structure
WAP to insert an element in Queue (using
9.
Array).
WAP to delete an element from Queue
10.
(using Array).
WAP for insertion in one way link
11.
list(dynamic).
WAP for deletion from one way link
12.
list(dynamic).
WAP for insertion in one way link
13.
list(dynamic).
14. WAP for deletion from one way link

2
list(dynamic).

15. A recursive program for Tree traversal.

Program 1 : Write a Program To Perform Insertion in Array:

SOURCE CODE :1

#include<stdio.h>

#include<conio.h>

#define size 5

intarr[size];

int last = -1;

void display()

int i=0;

printf("\n (Name - SIMRAN , Roll_No.- 24028115470022)\n Elements in


Array are : ");

while (i <=last)

printf("%d " , arr[i] );

i = i +1;

void insert()

3
{

int item;

if(last<size)

printf("\nEnter an item : ");

scanf("%d" , &item);

last = last + 1;

arr[last] = item;

else

printf("\nUnsufficient Memory !(Array is FULL) ");

void main()

char choice;

clrscr();

while(1)

printf(" \n Enter your choice : ");

printf("\n1. For insertion in Array");

printf("\n2. For Display items of Array");

printf("\n3. For Exit\n");

choice = getch();

switch(choice)

4
case '1':

insert();

break;

case '2':

display();

break;

case '3':

exit(0);

default:

printf("\nInvalid Choice Enter Choice Again!\n");

OUTPUT :

5
FIG. 1.0

2.Program :Write A Program To Perform Deletion in Array.

Source Code :

#include <stdio.h>

#include <conio.h>

voidinsertionSort(intarr[], int n) {

int i, key, j;

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

key = arr[i];

j = i - 1;

// Move elements that are greater than key one position ahead

6
while (j >= 0 &&arr[j] > key) {

arr[j + 1] = arr[j];

j = j - 1;

arr[j + 1] = key;

voidprintArray(intarr[], int n) {

int i;

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

printf("%d ", arr[i]);

printf("\n");

int main() {

intarr[100], n, i;

clrscr(); // Clear screen (specific to Turbo C)

printf("Enter number of elements: ");

scanf("%d", &n);

printf("Enter %d elements: ", n);

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

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

7
}

printf("\nOriginal array: ");

printArray(arr, n);

insertionSort(arr, n);

printf("\nSorted array: ");

printArray(arr, n);

getch(); // Wait for user input before closing (Turbo C specific)

return 0;

OUTPUT :

8
FIG.2.0

3.Program : Write a Program to perform to Bubble Sort on Array.

Source Code :

#include<stdio.h>

#include<conio.h>

#define SIZE 10

9
int main ()

int data[ SIZE ] = { 30, -21, 17, 90, -5, 22,13,1,27,225};

int pass, i, temp;

clrscr();

printf("Programmer Name = Simran , Roll_No.-24028115470022\n");

printf("\nOriginal order of data items:\n");

//printing data items

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

printf("%4d", data[ i ]);

//bubble sort

for (pass = 1; pass < SIZE; ++pass) //loop for number of passes

for (i = 0; i < SIZE - 1; ++i)

//comparing successive elements and swapping

if (data[ i ] > data[ i + 1])

temp = data[ i ];

data[ i ] = data[ i + 1 ];

data[ i + 1 ] = temp;

10
}

printf("\nData items in ascending order:\n");

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

printf("%4d", data[ i ]);

return 0 }

OUTPUT :

FIG.3.0

4.Program :write a program to perform to selection sort on array.

Source Code :

#include <stdio.h>

int main()

11
{

int array[100], n, c, d, position, t;

clrscr();

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]);

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

position = c;

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

if (array[position] > array[d])

position = d;

if (position != c)

t = array[c];

array[c] = array[position];

array[position] = t;

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

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

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

printf("\nProgrammer Name = Simran , Roll_No. - 24028115470022");

return 0;

OUTPUT :

Fig.4.0

Program 5 : Write a Program To Perform Insertion Sort in Array:

SOURCE CODE :5

#include <stdio.h>

int main()

13
int n, array[1000], c, d, t;

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]);

for (c = 1 ; c <= n - 1; c++) {

d = c;

while ( d > 0 && array[d] < array[d-1]) {

t = array[d];

array[d] = array[d-1];

array[d-1] = t;

d--;

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

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

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

} printf("programer SIMRAN rollno 24028115470022");

return 0;

14
}

OUTPUT:

FIG.5.0

Program .6.Write a program to perform Quick sort on array.

15
Source Code:

#include <stdio.h>

#define maxsize 100

void swap(int *a, int *b) {

int temp = *a;

*a = *b;

*b = temp;

clrscr();

int partition(int arr[], int low, int high) {

int pivot = arr[low];

int i = low + 1;

int j = high;

while (1) {

while (i <= j && arr[i] <= pivot)

i++;

while (i <= j && arr[j] > pivot)

16
j--;

if (i <= j) {

swap(&arr[i], &arr[j]);

} else {

swap(&arr[low], &arr[j]);

return j;

void quick_sort(int arr[], int low, int high) {

if (low < high) {

int pivot = partition(arr, low, high);

quick_sort(arr, low, pivot - 1);

quick_sort(arr, pivot + 1, high);

int main() {

17
int n, i;

int arr[maxsize];

printf("Enter the number of elements: ");

scanf("%d", &n);

printf("Enter the elements: ");

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

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

quick_sort(arr, 0, n - 1);

printf("PROGRAMER SIMRAN ,rollno 24028115470022 this Sorted Array: ");

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

printf("%d ", arr[i]);

return 0;

OUTPUT:

18
Fig.6

Program 7 :

Source Code :

#include <stdio.h>

#include<conio.h>

19
int linearSearch(int arr[], int n, int key ){

int i;

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

if(arr[i] == key)

return i;

return -1;

void main()

int arr[100], n, key, result,i;

char ch;

clrscr();

while(1){

printf("\nEnter number of elements : ");

scanf("%d", &n);

printf("\nEnter %d elements : ", n);

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

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

printf("Enter element to search: ");

scanf("%d", &key);

result = linearSearch(arr, n, key);

20
if (result != -1)

printf("Element found
at index: %d\n", result);

else

printf("\nElement not
found in the array.");

printf("\nProgramer SIMRAN , 24028115470022 Said Enter q to quit :");

scanf("%c",&ch);

if(ch=='q')

exit();

getch();

OUTPUT :

21
Fig.7.0

22
23
24
25

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy