Skip to content

Commit cbc29e8

Browse files
authored
Data Structure Implementation Using C
1 parent 424a301 commit cbc29e8

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

Data Structure Using C/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This is my Readme
2+
3+
I added my readme file in this repo.
4+
Happy to contribute to open source.

Data Structure Using C/stack/stack.c

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
#include <stdio.h>
3+
#define maxsize 10
4+
5+
int stack[maxsize], top = -1;
6+
7+
void push();
8+
void pop();
9+
void display();
10+
11+
12+
int main()
13+
{
14+
int choice;
15+
16+
do
17+
{
18+
printf("\n----stack----\n");
19+
printf("Press 1 for push\n");
20+
printf("Press 2 for pop\n");
21+
printf("Press 3 for display\n");
22+
printf("Press 4 for exit\n");
23+
printf("enter your choice: ");
24+
scanf("%d",&choice);
25+
26+
switch(choice)
27+
{
28+
case 1: push(); break;
29+
case 2: pop(); break;
30+
case 3: display(); break;
31+
case 4: break;
32+
default: printf("Invalid choice");
33+
}
34+
}while(choice!=4);
35+
}
36+
37+
void push()
38+
{
39+
if(top == maxsize - 1 )
40+
{
41+
printf("stack is overflow");
42+
}
43+
else
44+
{
45+
printf("enter value:");
46+
top++;
47+
scanf("%d",&stack[top]);
48+
}
49+
}
50+
void pop()
51+
{
52+
if(top == -1){
53+
printf("stack is empty");
54+
}
55+
else
56+
{
57+
printf("deleted item %d",stack[top]);
58+
top--;
59+
}
60+
}
61+
void display()
62+
{
63+
if (top == -1)
64+
{
65+
printf("stack is empty");
66+
}
67+
else
68+
{
69+
for(int i =0; i<=top; i++)
70+
{
71+
printf("%d\t",stack[i]);
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)