Skip to content

Commit 4e1f258

Browse files
authored
Add files via upload
1 parent 9867225 commit 4e1f258

File tree

94 files changed

+3854
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3854
-0
lines changed

ADT_Array_as_Queue_Circuler.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// author: jaydattpatel
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <conio.h>
5+
6+
#define n 5
7+
int cq[10],front =-1, rear = -1,item;
8+
9+
void insert()
10+
{
11+
if(front == ((rear+1)%(n-1)))
12+
{ printf("Queue overflow !!\n"); return; }
13+
else
14+
{
15+
printf("\nEnter Value:"); scanf("%d",&item);
16+
if(front == -1) front = rear = 0 ;
17+
else rear = ((rear+1)%(n-1));
18+
cq[rear] = item;
19+
printf("Insertion Successfull !!\n");
20+
display();
21+
}
22+
}
23+
24+
void delete()
25+
{
26+
if(front == -1) printf("Queue underflow !!!\n");
27+
else
28+
{
29+
item = cq[front];
30+
printf("Elements deleted from queues.\n");
31+
cq[front] = NULL;
32+
if(front == rear) front = rear = -1;
33+
else front = ((front+1)%(n-1));
34+
display();
35+
}
36+
}
37+
void display()
38+
{
39+
int i;
40+
if(front == -1) printf("Queue is emplty !!!\n");
41+
else
42+
{
43+
if (front <= rear)
44+
{ for(i=front;i<=rear;i++) printf("%d\n",cq[i]);}
45+
46+
if (front > rear)
47+
{
48+
for(i=front;i<=n-1;i++) printf("%d\n",cq[i]);
49+
for(i=front;i<=rear;i++) printf("%d\n",cq[i]);
50+
}
51+
printf("front queue is %d\n",cq[front]);
52+
printf("rear queue is %d\n",cq[rear]);
53+
}
54+
}
55+
56+
int main()
57+
{
58+
int value,choice;
59+
while(1)
60+
{
61+
printf("\n--------queue implement Menu -------------");
62+
printf("\n1.Insert\t2.Delete\t3.Display\t4.Exit");
63+
printf("\nEnter your choice:");
64+
scanf("%d",&choice);
65+
switch(choice)
66+
{
67+
case 1:{insert(); break;}
68+
case 2:{delete(); break;}
69+
case 3:{display(); break;}
70+
case 4:{exit(0);}
71+
default:{printf("\nFunction Terminated."); exit(0);}
72+
}
73+
}
74+
return(0);
75+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// author: jaydattpatel
2+
#include<stdio.h>
3+
#include<ctype.h>
4+
5+
char stack[100];
6+
int top = -1;
7+
8+
void push(char x)
9+
{stack[++top] = x;}
10+
11+
char pop()
12+
{
13+
if(top == -1) return(-1);
14+
else return(stack[top--]);
15+
}
16+
17+
int priority(char x)
18+
{
19+
if(x == '(') return 0;
20+
if(x == '+' || x == '-') return 1;
21+
if(x == '*' || x == '/') return 2;
22+
return 0;
23+
}
24+
25+
int main()
26+
{
27+
char exp[100];
28+
char *e, x;
29+
printf("Enter the expression : ");
30+
scanf("%s",exp);
31+
printf("\n");
32+
e = exp;
33+
34+
while(*e != '\0')
35+
{
36+
if(isalnum(*e)) printf("%c ",*e);
37+
else if(*e == '(') push(*e);
38+
else if(*e == ')')
39+
{
40+
while((x = pop()) != '(') printf("%c ", x);
41+
}
42+
else
43+
{
44+
while(priority(stack[top]) >= priority(*e))
45+
printf("%c ",pop());
46+
push(*e);
47+
}
48+
e++;
49+
}
50+
51+
while(top != -1) printf("%c ",pop());
52+
53+
return 0;
54+
}

ADT_Array_as_stack_push_pop.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// author: jaydattpatel
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
#define MAXSTK 10
6+
int stk[MAXSTK], top = -1;
7+
8+
void push()
9+
{
10+
if(top >= (MAXSTK-1))
11+
{printf("\nStack is Full !! Insertion not possible");}
12+
else
13+
{ int value;
14+
printf("\nEnter Value:"); scanf("%d",&value);
15+
top++; stk[top] = value;
16+
printf("\nInsertion Successfull !!");
17+
}
18+
};
19+
void pop()
20+
{
21+
if(top == -1)
22+
{printf("\nStack is Empty !! Deletion not possible");}
23+
else
24+
{
25+
printf("\nDeleted : %d",stk[top]);
26+
stk[top] = 0; top--;
27+
}
28+
};
29+
30+
void display()
31+
{
32+
if(top == -1) {printf("\nStack is Empty !!");}
33+
else
34+
{
35+
int i;
36+
printf("\nStack Elements are :\n ");
37+
for(i=top;i>=0;i--)
38+
printf("%d\n",stk[i]);
39+
}
40+
};
41+
42+
int main()
43+
{
44+
int value,choice;
45+
while(1)
46+
{
47+
printf("\n-----------Menu -------------");
48+
printf("\n1.Push\t2.Pop\t3.Display\t4.Exit");
49+
printf("\nEnter your choice:");
50+
scanf("%d",&choice);
51+
switch(choice)
52+
{
53+
case 1:{push(); break;}
54+
case 2:{pop(); break;}
55+
case 3:{display(); break;}
56+
case 4:{exit(0);}
57+
default:{printf("\nFunction Terminated."); exit(0);}
58+
}
59+
}
60+
return(0);
61+
}

ADT_Binary_Tree.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Recursive C program for level order traversal of Binary Tree
2+
// author: jaydattpatel
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
6+
/* A binary tree node has data,pointer to left child and a pointer to right child */
7+
struct node {
8+
int data;
9+
struct node *left, *right;
10+
};
11+
12+
/* Function prototypes */
13+
void printCurrentLevel(struct node* root, int level);
14+
int height(struct node* node);
15+
struct node* newNode(int data);
16+
17+
/* Function to print level order traversal a tree*/
18+
void printLevelOrder(struct node* root)
19+
{
20+
int h = height(root);
21+
int i;
22+
for (i = 1; i <= h; i++)
23+
printCurrentLevel(root, i);
24+
}
25+
26+
/* Print nodes at a current level */
27+
void printCurrentLevel(struct node* root, int level)
28+
{
29+
if (root == NULL)
30+
return;
31+
if (level == 1)
32+
printf("%d ", root->data);
33+
else if (level > 1) {
34+
printCurrentLevel(root->left, level - 1);
35+
printCurrentLevel(root->right, level - 1);
36+
}
37+
}
38+
39+
// Compute the "height" of a tree -- the number of nodes along the longest path from the root node down to the farthest leaf node.
40+
int height(struct node* node)
41+
{
42+
if (node == NULL)
43+
return 0;
44+
else {
45+
/* compute the height of each subtree */
46+
int lheight = height(node->left);
47+
int rheight = height(node->right);
48+
49+
/* use the larger one */
50+
if (lheight > rheight)
51+
return (lheight + 1);
52+
else
53+
return (rheight + 1);
54+
}
55+
}
56+
57+
// Helper function that allocates a new node with the given data and NULL left and right pointers.
58+
struct node* newNode(int data)
59+
{
60+
struct node* node
61+
= (struct node*)malloc(sizeof(struct node));
62+
node->data = data;
63+
node->left = NULL;
64+
node->right = NULL;
65+
66+
return (node);
67+
}
68+
69+
int main()
70+
{
71+
struct node* root = newNode(1);
72+
root->left = newNode(2);
73+
root->right = newNode(3);
74+
root->left->left = newNode(4);
75+
root->left->right = newNode(5);
76+
root->right->left = newNode(6);
77+
root->right->right = newNode(7);
78+
79+
printf("Level Order traversal of binary tree is \n");
80+
printLevelOrder(root);
81+
82+
return 0;
83+
}

ADT_Binary_Tree_create.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* The ADT Binary Tree
2+
*/
3+
// author: jaydattpatel
4+
#include<stdio.h>
5+
#include<stdlib.h>
6+
7+
struct node
8+
{
9+
char data;
10+
struct node *left;
11+
struct node *right;
12+
};
13+
14+
typedef struct node *BTREE;
15+
//typedef NODE ;
16+
17+
void inorder (BTREE root)
18+
{
19+
if (root != NULL)
20+
{
21+
inorder(root ->left);
22+
printf("%c\t", root ->data);
23+
inorder(root -> right);
24+
}
25+
}
26+
27+
28+
BTREE init_node (char d1, BTREE p1, BTREE p2)
29+
{
30+
BTREE new_node;
31+
new_node = (BTREE)(malloc(sizeof(struct node)));
32+
new_node->data = d1;
33+
new_node->left = p1;
34+
new_node->right = p2;
35+
return new_node;
36+
}
37+
BTREE create_tree(char data[], int i, int size)
38+
{
39+
if (i >= size)
40+
return NULL;
41+
else
42+
return(init_node( data[i], create_tree(data, 2*i + 1, size), create_tree(data, 2*i + 2, size) ));
43+
}
44+
45+
int main()
46+
{
47+
char data[] = {'A', 'B', 'C', 'D', 'E'};
48+
BTREE b;
49+
b = create_tree(data, 0, 5);
50+
inorder(b);
51+
printf("\n\n");
52+
return 0;
53+
}

0 commit comments

Comments
 (0)