#include<stdio.h>
#include<stdlib.h>
struct StackRecord
{
int Capacity;
int TopOfStack;
int *Array;
};
typedef struct StackRecord *Stack;
Stack CreateStack(int Length)
{
Stack S;
S = (Stack)malloc (sizeof (struct StackRecord));
S->Array = (int *)malloc (Length * sizeof (int ));
S->Capacity = Length;
S->TopOfStack = -1 ;
return S;
}
void DisposeStack(Stack S)
{
if (S != NULL)
{
free (S->Array);
free (S);
}
}
int IsEmpty(Stack S)
{
return S->TopOfStack == -1 ;
}
int IsFull(Stack S)
{
return S->Capacity == (S->TopOfStack+1 );
}
void MakeEmpty(Stack S)
{
S->TopOfStack = -1 ;
}
void Push(int x, Stack S)
{
if (IsFull(S))
{
printf ("Full Stack\n" );
return ;
}
else
S->Array[++ S->TopOfStack] = x;
}
int Top(Stack S)
{
if (!IsEmpty(S))
return (S->Array[S->TopOfStack]);
printf ("Empty Stack\n" ); return 0 ;
}
int Pop(Stack S)
{
if (IsEmpty(S))
{
printf ("Empty Stack\n" );
return ;
}
else
return (S->Array[S->TopOfStack--]);
}
int TopAndPop(Stack S)
{
if (!IsEmpty)
return (S->Array[S->TopOfStack--]);
printf ("Empty Stcak\n" );
return 0 ;
}
#include < stdio. h>
#include < stdlib. h>
struct Node
{
double a;
struct Node * next;
};
typedef struct Node * Stack ;
Stack CreakStack()
{
Stack S;
S = (Stack )malloc(sizeof(Node));
S-> next = NULL ;
return S;
}
void Push(char c, Stack S)
{
Stack tmp;
tmp = (Stack )malloc(sizeof(Node));
tmp-> a = c;
tmp-> next = S-> next;
S-> next = tmp;
}
void Pop(Stack S)
{
Stack tmp;
tmp = S-> next;
S-> next = tmp-> next;
free(tmp);
}
char Top(Stack S)
{
return (S-> next-> a);
}
bool Isempty(Stack S)
{
return S-> next == NULL ;
}