cs project
cs project
➢ Binary Search
➢ Linear Search
➢ Bubble sort
➢ Push and Pop in stack using Link List
➢ Enqueue and Dequeue using Link List
➢ Linked List creation and display
➢ Conclusion
➢ Acknowledgement
Binary Search
Source code
#include <stdio.h>
int left = 0;
if (arr[mid] == target)
return mid;
left = mid + 1;
else
right = mid - 1; }
return -1; }
int main() {
int target;
scanf("%d",&target);
if (result == -1)
else {
If found
If not found
Linear search
Source code
#include <stdio.h>
if (arr[i] == key) {
return i; } }
return -1;
int main() {
int arr[] = {10, 20, 80, 30, 60, 50, 110, 100};
int key;
scanf("%d", &key);
if (result == -1) {
} else {
return 0;
}
Linear search
Output
If found
If not found
Bubble sort
Source code
#include <stdio.h>
int i, j, temp;
int swapped;
swapped = 0;
temp = arr[j];
arr[j + 1] = temp;
swapped = 1; }
if (swapped == 0)
break; }}
printf("\n");}
int main() {
printArray(arr, n);
bubbleSort(arr, n);
printArray(arr, n);
return 0; }
Bubble sort
Output
Push and Pop in Stack using
Link List
Source code
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
if (newNode == NULL) {
exit(1);
newNode->data = data;
newNode->next = NULL;
return newNode;
newNode->next = *top;
*top = newNode;
return -1; }
*top = (*top)->next;
free(temp);
return poppedData; }
if (isEmpty(top)) {
printf("Stack is empty\n");
return; }
current = current->next; }
printf("\n"); }
void menu() {
printf("1. Push\n");
printf("2. Pop\n");
printf("3. Display\n");
printf("4. Exit\n");
int main() {
while (1) {
menu();
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &data);
push(&top, data);
break;
case 2:
if (!isEmpty(top)) {
} else {
pop(&top);
break;
case 3:
display(top);
break;
case 4:
printf("Exiting program...\n");
while (!isEmpty(top)) {
pop(&top);
return 0;
default:
return 0;
}
Push and Pop in Stack using Link
List
Output
Enqueue and Dequeue using Link
List
Source code
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Queue {
};
if (newNode == NULL) {
exit(1);
newNode->data = data;
newNode->next = NULL;
return newNode;
return queue;
newNode->next = queue->front;
queue->front = newNode;
if (queue->rear == NULL) {
queue->rear = newNode;
return;
current = queue->front;
prev = NULL;
prev = current;
current = current->next;
prev->next = newNode;
newNode->next = current;
if (current == NULL) {
queue->rear = newNode;
if (isEmpty(queue)) {
printf("Queue Underflow! Cannot dequeue\n");
return -1;
queue->front = queue->front->next;
if (queue->front == NULL) {
queue->rear = NULL; }
free(temp);
return data; }
if (isEmpty(queue)) {
printf("Queue is empty\n");
return; }
current = current->next; }
printf("\n");}
void menu() {
printf("1. Enqueue\n");
printf("2. Dequeue\n");
printf("3. Display\n");
printf("4. Exit\n");
int main() {
while (1) {
menu();
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &data);
enqueue(queue, data);
break;
case 2:
if (!isEmpty(queue)) {
} else {
dequeue(queue); }
break;
case 3:
display(queue);
break;
case 4:
printf("Exiting program...\n");
while (!isEmpty(queue)) {
dequeue(queue); }
free(queue);
return 0;
default:
} }
return 0; }
Enqueue and Dequeue using Link
List
Output
Link List Creation and Display
Source code
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
newNode->data = data;
newNode->next = NULL;
return newNode;
if (head == NULL)
return newNode;
temp = temp->next; }
temp->next = newNode;
return head;
}
void displayList(struct Node* head) {
if (head == NULL) {
printf("List is empty\n");
return; }
temp = temp->next;
printf("NULL\n");
int main()
displayList(head);
return 0;
}
Link List Creation and Display
Output
Conclusion
In this project, I explored the various aspects of fundamental
data structures and algorithms including Binary Search,
Linear Search, Bubble Sort, stack operations (push and pop)
using a linked list, queue operations (enqueue and dequeue)
using a linked list, and linked list creation and display, all
implemented in C. Through practical implementation and
experimentation, I gained a deeper understanding of how
these algorithms and data structures work, their efficiency,
and their applications. This project helped me enhance my
skills in programming with C and working with dynamic
memory management, which will be beneficial for future
applications in software development and problem-solving.
Overall, this project has been an enriching learning
experience, reinforcing my knowledge of core computer
science concepts and their real-world uses. It has inspired
me to further explore and improve my understanding of
algorithms and data structures in future projects.
Acknowledgement
I would like to express my sincere gratitude to my computer
teacher, Mr./Mrs.,__________________for their valuable
guidance and support throughout this project. Their
encouragement and assistance have been instrumental in
helping me complete my work successfully, especially in
understanding and implementing concepts like Binary
Search, Bubble Sort, and linked list operations in C.A
special thanks to my family and friends, whose constant
encouragement and motivation have been a great source of
support during this project. Their belief in me has helped me
stay focused and complete my work with dedication .Finally,
I appreciate the knowledge and skills I have gained while
working on this project, which has been a valuable learning
experience in deepening my understanding of data
structures and algorithms.
………………………… …………………………
Signature of the student Signature of the teacher