0% found this document useful (0 votes)
4 views28 pages

C Programming Data Structures Experiments

The document is a practical file for a Computer Science and Engineering course at Amity University Haryana, detailing various experiments conducted by a student named Deep. It includes objectives, theories, and code implementations for operations on data structures such as arrays, stacks, queues, linked lists, and binary search trees. The file serves as a record of the student's learning outcomes and practical skills in data structure algorithms.

Uploaded by

mohity4536641
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)
4 views28 pages

C Programming Data Structures Experiments

The document is a practical file for a Computer Science and Engineering course at Amity University Haryana, detailing various experiments conducted by a student named Deep. It includes objectives, theories, and code implementations for operations on data structures such as arrays, stacks, queues, linked lists, and binary search trees. The file serves as a record of the student's learning outcomes and practical skills in data structure algorithms.

Uploaded by

mohity4536641
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

DSC PRACTICAL FILE

[CSEU3208]

(Assistant Professor), ASET STUDENT NAME: Deep

Roll NO: A50124624004

SEMESTER: 3
FACULTY NAME: DR. Shivani Sharma

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


AMITY UNIVERSITY HARYANA, INDIA

Index
[Link] Experiment CO Date of Date of [Link] Sign
covere experiment submission
d
1. Perform traversing operation CO.1 06/08/25 06/08/25 1-2
using array in c.

2. Perform insertion operation CO.1 13/08/25 13/08/25 3-4


using array in C

3. Perform deletion operation CO.1 20/08/25 20/08/25 5-6


using array in C

4 Perform PUSH and POP CO.2 27/08/25 27/08/25 7-9


operations in stack using C

5 Perform Insertion elements in CO.3 03/09/25 03/09/25 10-11


queue using C

6 CO.3 18/09/25 18/09/25 12-13


Perform delete elements in queue
using C
7 Perform insertion operations CO.4 25/09/25 25/09/25 14-15
in linked list

8 Perform deletion operations in CO.4 9/10/25 9/10/25 16-19


linked list
9 Demonstrate circular singly CO.4 16/10/25 16/10/25 20-22
linked list
10 Searching and Deletion in CO.5 30/10/25 30/10/25 23-28
Binary Search tree
11

12

13

14

15

Shivam A50124624001
Student Name : Shivam
Semester /course : 3/Btech ( EEE )
Date: 13/08/2025
Faculty Signature:
Remarks:

Experiment No: 1

Objective:
1. Perform traversing operation using array in c.
Program Outcome:
Student get knowledge of array using traversing operation of
data structure.

Theory:
An array is a collection of elements stored in contiguous memory
locations. Each element can be accessed using an index.

Operations:

Traversing means visiting each element of the array exactly once,


typically for operations like printing, searching, or modifying elements.

Code:
#include <stdio.h> int main() { int arr[6] = {31,1,20,06,2,11}; //

Array declaration and initialization

int i;

printf("Traversing the array elements:\n");

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

printf("Element at index %d: %d\n", i, arr[i]); // Accessing each element

Shivam A50124624001
}

return 0;

Experiment No: 2
Objective:
Perform insertion operation using array in c.

Theory:
An array is a collection of elements stored in contiguous
memory locations. Each element can be accessed using an
index.

Operations:

• Insertion operation: Insertion means adding a new element at a specific position in


the array..

Code:
#include <stdio.h> int main() {

int arr[10] = {54, 9, 35, 81,


Shivam A50124624001
99}; int size = 5; int i, pos = 2,

value = 4; printf("Original

array:\n"); for (i = 0; i < size;

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

// Shift elements to the right


for (i = size; i > pos; i--)
{ arr[i] = arr[i - 1];
}
arr[pos] = value; size++; printf("\n\nArray after insertion of %d at
position %d:\n", value, pos); for (i = 0; i < size; i++)
{ printf("%d ", arr[i]);
}
return 0;
}

Shivam A50124624001
Experiment No: 3
Objective:-
Perform deletion operation using array in c.

Theory:
An array is a collection of elements stored in contiguous memory
locations. Each element can be accessed using an index.
Operation :- Deletion means removing an element from a specific position

#include <stdio.h> int main()

{ int arr[10] =

{14,29,33,48,57}; int size =

5; int i, pos = 2;

printf("Original array:\n");

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

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

// Shift elements to the left

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

arr[i] = arr[i + 1];

} size--; printf("\n\nArray after deletion at position

%d:\n", pos); for (i = 0; i < size; i++) {

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

return 0;

Shivam A50124624001
}

Shivam A50124624001
Experiment No: 4
Objective
3(a): Perform PUSH operation in stack using C.

3(b): Perform POP operation in stack using C.

Program Outcome:

Students are able to learn and gain knowledge about stacks and operation implementing
included in Data Structures and Algorithms.

Theory:
Stack is a linear data structure that follows LIFO (Last In First Out) Principle, the last
element inserted is the first to be popped out. It means both insertion and deletion
operations happen at one end only.

Operations:

1. Push Operation: The Push operation refers to inserting an element in the stack.
There's only one position at which the new element can be inserted: at the Top of the
stack.

2. POP Operation: It removes the topmost element from the stack and returns that
element's value. This is the only way to remove elements. After a pop , the element
that was previously second from the top becomes the new top.

Code:

#include <stdio.h> #define

SIZE 5 int stack[SIZE]; //

Stack array int top = -1;

// push an element void push(int value) { if (top ==

SIZE - 1) { printf("Stack Overflow! Cannot push

%d\n", value); } else { top++; stack[top] =

value; printf("%d pushed to stack\n", value);

Shivam A50124624001
}

// pop an element void pop() { if (top == -1) {

printf("Stack Underflow! Nothing to pop\n");

} else { printf("%d popped from stack\n",

stack[top]);

top--;

}// display the stack void

display() { if (top == -1) {

printf("Stack is empty.\n");

} else { printf("Stack

elements: "); for (int i = 0; i

<= top; i++) { printf("%d

", stack[i]);

printf("\n");

} } int

main()

{ push(5

0);

push(40);

push(75);

push(90);

display();

Shivam A50124624001
pop();

display();

pop();

pop();

pop();

display();

return 0;

}
Experiment No: 5
Objective:

Insert 10 elements in queue using put() function.

Program Outcome:

Students are able to learn and gain knowledge about queue and operation implementing
included in Data Structures and Algorithms.

Theory:

A queue in C is a linear data structure that follows the First-In-First-Out (FIFO) principle,
meaning the first element added to the queue will be the first one removed. It functions like a
waiting line where elements are added at one end (the "rear") and removed from the other
end (the "front").

Shivam A50124624001
Code:
#include <stdio.h> int main() { int queue[7]; int

front = 0, rear = -1; printf("Enter 5 elements to

insert into the queue:\n"); for (int i = 0; i < 5; i++) {

int value; printf("Element %d: ", i + 1); scanf("%d",

&value);

rear++;

queue[rear] = value;

printf("\nQueue elements are:\n");

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

{ printf("%d ", queue[i]);

} printf("\

n"); return 0;

Shivam A50124624001
Experiment No: 6
Objective:

Delete 5 elements in queue using get() function.

Program Outcome:

Students are able to learn and gain knowledge about queue and operation implementing
included in Data Structures and Algorithms.

CODE :-

#include <stdio.h> int main() { int queue[10] =

{67,87,90,23,61,34,82,78,56,30}; // Predefined queue int front = 0,

rear = 9; // Queue has 10 elements printf("Original Queue:\n"); for

(int i = front; i <= rear; i++) { printf("%d ", queue[i]); } // Delete 5

elements printf("\n\nDeleting 5 elements from the queue:\n");

for (int i = 0; i < 5; i++) { if (front > rear)

{ printf("Queue Underflow! No more elements to delete.\

n");

Shivam A50124624001
break;

printf("Deleted element: %d\n", queue[front]);

front++;

printf("\nRemaining elements in the queue:\n");

if (front > rear)

{ printf("Queue is empty.\

n");

} else { for (int i = front; i <=

rear; i++) { printf("%d ",

queue[i]);

printf("\n");

return 0;

Shivam A50124624001
Experiment No. 7
Objective:

To perform insertion operation in linked list.

Program outcome:
Students are able to learn and gain knowledge about linked list and
operation implementing included in Data Structures and Algorithms.

Theory:
A linked list is a linear data structure where each element (node) contains:

• Data
• A pointer to the next node

Insertion Operation: Insertion can be done at:

• Beginning
• End
• Specific position

CODE:

Shivam A50124624001
#include <stdio.h>

#include <stdlib.h>

struct Node {

int data; struct

Node* next;

};

void insertAtBeginning(struct Node** head, int value) { struct

Node* newNode = (struct Node*)malloc(sizeof(struct Node));

newNode->data = value; newNode->next = *head;

*head = newNode;

void printList(struct Node* head) {

while (head != NULL)

{ printf("%d -> ", head->data);

head = head->next;

printf("NULL\n");

int main() { struct Node* head

= NULL;

insertAtBeginning(&head, 65);

insertAtBeginning(&head, 87);

insertAtBeginning(&head, 89);

printList(head); return 0;
Shivam A50124624001
}

Experiment No: 8
Objective: To perform deletion operation in linked list.

Program outcome:
Students are able to learn and gain knowledge about linked list and
operation implementing included in Data Structures and Algorithms.

Theory:
A linked list is a linear data structure where each element (node) contains:

• Data
• A pointer to the next node

Deletion Operation:Deletion can be done from:

• Beginning
• End
• Specific postion

CODE:

#include <stdio.h>

#include

<stdlib.h> struct

Node{ int data;

struct Node*next;

Shivam A50124624001
};

struct Node*head=NULL;

void insert(int value){ struct Node*newNode=(struct

Node*)malloc(sizeof(struct Node)); newNode->data=value;

newNode->next=NULL;

if(head==NULL)

{ head=newNode;

}else{ struct

Node*temp=head;

while(temp->next!

=NULL) temp=temp-

>next; temp-

>next=newNode;

}}

void display(){ struct

Node*temp=head;

if(temp==NULL){

printf("List is empty.\n");

return;

} printf("List:

");

while(temp!=NULL)

{ printf("%d -> ",temp->data);

temp=temp->next;
Shivam A50124624001
}

printf("NULL\n");

void deleteBeginning(){ if(head==NULL)

printf("List is empty.\n"); return;

struct Node*temp=head;

head=head->next;

free(temp); printf("First node

deleted.\n");

void deleteEnd(){ if(head==NULL)

printf("List is empty.\n");

return;

if(head->next==NULL)

{ free(head);

head=NULL;

printf("Last node deleted.\n");

return;

Shivam A50124624001
struct Node*temp=head;

while(temp->next->next!=NULL)

temp=temp->next; free(temp-

>next); temp->next=NULL;

printf("Last node deleted.\n");

int main()

{ insert(56);

insert(87);

insert(39);

display();

deleteBeginning()

; display();

deleteEnd();

display(); return

0;

Shivam A50124624001
Experiment No. 09

Objective:

To demostrate a circular singly linked list.

Program outcomes:

Understanding Circular Singly Linked Lists helps students master pointer logic and
dynamic memory handling. It builds a strong foundation for real-world applications
like scheduling, buffering, and cyclic data traversal.

Theory:

A Circular Singly Linked List is a variation of a singly linked list where the last
node points back to the first node, forming a circle.

Key Characteristics:

• Each node contains data and a next pointer.


• The last node’s next points to the first node, not NULL.
• No node has a NULL pointer — this makes traversal circular.

Code:

#include <stdio.h>

#include <stdlib.h>

struct Node {

int data; struct

Node* next;

};

Shivam A50124624001
struct Node* head = NULL; // insert at the end void insert(int data) {

struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));

newNode->data = data;

if (head == NULL) { head = newNode;

newNode->next = head; // Circular link

} else { struct Node*

temp = head; // Traverse to last

node while (temp->next !=

head) { temp = temp-

>next;

temp->next = newNode; newNode->next = head; //

New node points to head

}// display the list void

display() { if (head ==

NULL) { printf("List is

empty.\n"); return;

struct Node* temp = head;

printf("Circular Linked List: ");

do { printf("%d -> ", temp-

>data); temp = temp->next;

} while (temp != head);


Shivam A50124624001
printf("(back to head)\n");

int main()

{ insert(78);

insert(94);

insert(20);

insert(123);

display();

return 0;

Experiment No. 10

Objective:

7(a). To perform searching operation in Binary Search Tree (BST).

7(b). - To perform deletion operation in Binary Search Tree (BST).

Program Outcome:

Students will be able to understand and implement searching and deletion


operations in a Binary Search Tree using C programming and learn how data can be
efficiently stored, searched, and modified in tree structures.

Shivam A50124624001
Theory:

A Binary Search Tree (BST) is a non-linear data structure in which:

• The left child of a node contains a value less than the node’s value.
• The right child of a node contains a value greater than the node’s value.

Searching Operation:
• Start from the root node.
• If the key matches the node’s value, the search is successful.
• If the key is smaller, search the left subtree; if larger, search the right subtree.

Deletion Operation:
• Deletion in BST has three possible cases:
o Node to be deleted is a leaf – simply remove it. o Node to be
deleted has one child – replace it with its child.
o Node to be deleted has two children – replace it with its inorder
successor (smallest node in the right subtree).

CODE:-
#include <stdio.h>

#include <stdlib.h>

struct Node {

int data;

struct Node* left;

struct Node* right;

};

struct Node* createNode(int value) { struct Node* newNode =

(struct Node*)malloc(sizeof(struct Node)); newNode->data =

value; newNode->left = newNode->right = NULL; return

newNode;

Shivam A50124624001
struct Node* insert(struct Node* root, int value)

{ // If the tree is empty, return a new node

if (root == NULL) return

createNode(value); // Otherwise, recur down

the tree if (value < root->data) root->left

= insert(root->left, value); else if (value >

root->data) root->right = insert(root->right,

value); return root;

//SEARCH A VALUE

struct Node* search(struct Node* root, int key) { //

Base Cases: root is null or key is present at root

if (root == NULL || root->data == key) return

root;

if (root->data < key) return

search(root->right, key); return

search(root->left, key);

struct Node* findMin(struct Node* node) {

struct Node* current = node; while

(current && current->left != NULL)

current = current->left; return current;

// FUNCTION TO DELETE A NODE


Shivam A50124624001
struct Node* deleteNode(struct Node* root, int key) {

// Base case: If the tree is empty if (root

== NULL) return root; if (key < root-

>data) root->left = deleteNode(root->left,

key); else if (key > root->data) root-

>right = deleteNode(root->right, key); else {

// Case 1: Node with only one child or no

child if (root->left == NULL) { struct

Node* temp = root->right; free(root);

return temp;

} else if (root->right == NULL) {

struct Node* temp = root->left;

free(root); return temp;

struct Node* temp = findMin(root->right);

root->data = temp->data; root->right =

deleteNode(root->right, temp->data);

return root;

void inorder(struct Node* root) {

if (root != NULL)

{ inorder(root->left);

Shivam A50124624001
printf("%d ", root->data);

inorder(root->right);

}}

int main() { struct Node*

root = NULL; root =

insert(root, 50);

insert(root, 30);

insert(root, 70);

insert(root, 20);

insert(root, 40);

insert(root, 60);

insert(root, 80);

printf("Inorder traversal of

original tree:\n");

inorder(root); printf("\n\

n"); int keyToFind = 40;

if (search(root, keyToFind) !

= NULL)

printf("Element %d found in

the BST.\n", keyToFind);

else printf("Element

%d not found in the BST.\

n", keyToFind);

keyToFind = 99; if

Shivam A50124624001
(search(root, keyToFind) !=

NULL) printf("Element

%d found in the BST.\n",

keyToFind); else

printf("Element %d not

found in the BST.\n",

keyToFind); printf("\

nDeleting 20 (leaf node)...\

n"); root =

deleteNode(root, 20);

printf("Inorder traversal

after deleting 20:\n");

inorder(root); printf("\n\

nDeleting 30 (node with one

child)...\n"); root =

deleteNode(root, 30);

printf("Inorder traversal

after deleting 30:\n");

inorder(root);

printf("\n\nDeleting 50 (node with two children)...\

n"); root = deleteNode(root, 50); printf("Inorder

traversal after deleting 50:\n"); inorder(root);

printf("\n"); return 0;

Shivam A50124624001
Shivam A50124624001

You might also like