Skip to content

Commit

Permalink
Pending changes exported from your codespace
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhangi47 committed Jan 18, 2024
1 parent 88051a7 commit e68474f
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions stack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <stdio.h>

typedef struct stack
{
char data[64];
int top;
} stack;
int empty(stack *p)
{
return (p->data == -1);
}
int top(stack *p)
{
return (p->data[p->top]);
}
void push(stack *p, char a)
{
p->data[++(p->top)] = a;
return;
}
void pop(stack *p)
{
if (!empty(&p))
{
p->top--;
}
return;
}
int main()
{
stack s;
s.top = -1;
char str[10] = "ABCDE";
int i, len;
len = sizeof(str);
for (i = 0; i < len; i++)
{
push(&s, str[i]);
}
printf(" string\n ");
for (i = 0; i < len; i++)
{
printf("%c", s.data[i]);
}
printf("\n");
printf(" reverse string\n ");
for (i = 0; i < len; i++)
{
printf("%c", top(&s));
pop(&s);
}
printf("\n");

return 0;
}

0 comments on commit e68474f

Please sign in to comment.