Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Data-Structure-In-C
This is a repository used to host various programs in c language as a part of our Data Structure lab.The programs that have been completed so far are
1. Linked list implementation in C
2. Stack implementation using array
3. Stack implementation using linked list
4. Queue implementation using array
5. Queue implementation using linked list
6. Creation of a polynomial using linked list
7. Addition of a polynomial using linked list
8. Implementation of doubly ended queue in C
9. Conversion and evaluation of infix expressions to postfix expressions using stack.
This is a repository used to host various programs in C language as a part of our Data Structure lab.The programs that have been completed so far are

1. Different Searching methods
2. Different Sorting methods
3. Linked list implementation in C
4. Stack implementation using array
5. Stack implementation using linked list
6. Queue implementation using array
7. Queue implementation using linked list
8. Creation of a polynomial using linked list
9. Addition of a polynomial using linked list
10. Implementation of doubly ended queue in C
11. Conversion and evaluation of infix expressions to postfix expressions using stack.
65 changes: 54 additions & 11 deletions searching/binaryTreeSearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include<stdio.h>
#include<stdlib.h>


struct node {
int data;
struct node *lc, *rc;
}*root = NULL;


struct node *createNode(int item)
{
struct node *n;
Expand All @@ -20,6 +22,7 @@ struct node *createNode(int item)
return n;
}


void inorder(struct node *r)
{
struct node *ptr;
Expand All @@ -33,19 +36,23 @@ void inorder(struct node *r)
}

}


void preorder(struct node *r)
{
struct node *ptr;
ptr = r;

if(ptr != NULL)
{
{
printf(" %d ", ptr -> data);
preorder(ptr -> lc);
preorder(ptr -> rc);
}

}


void postorder(struct node *r)
{
struct node *ptr;
Expand All @@ -54,12 +61,13 @@ void postorder(struct node *r)
if(ptr != NULL)
{
postorder(ptr -> lc);
postorder(ptr -> rc);
printf(" %d ", ptr -> data);
postorder(ptr -> rc);
printf(" %d ", ptr -> data);
}

}


void insertion()
{
int item, flag = 0;
Expand Down Expand Up @@ -108,18 +116,53 @@ void insertion()
}
}
}

printf("Inorder:");
printf("\n");
printf(" INORDER : ");
inorder(root);
printf("\n");
printf("Preorder: ");
printf(" PREORDER : ");
preorder(root);
printf("\n");
printf("Postorder: ");
printf(" POSTODER : ");
postorder(root);
printf("\n");
}


void search()
{
int ele, flag = 0;
struct node *ptr;
printf("\n Enter your element to be searched : ");
scanf("%d", &ele);

ptr = root;
while (ptr != NULL && flag != 1)
{
if(ptr -> data < ele)
{
ptr = ptr -> rc;
}
else if(ptr -> data > ele)
{
ptr = ptr -> lc;
}
else
{
flag = 1;
printf("\n Element FOUND !!!!!! :) ");
break;
}
}
if (flag == 0)
{
printf("\n Element NOT FOUND !!!! :( ");
}

printf("\n");
}


void main()
{
int ch;
Expand All @@ -131,11 +174,11 @@ void main()
switch(ch)
{
case 1: insertion();
break;
//case 2: search();
// break;
break;
case 2: search();
break;
case 3: exit(0);
break;
break;
default : printf("\n INVALID CHOICE !!!! ;( ");
}
}
Expand Down