// stack setup by C that use struct and one way array !
#include "stdafx.h"
#include "stdio.h"
#define MAX 10
typedef struct
{
char Name[30];
int age;
}IMFORMATION;
typedef struct
{ int top;
IMFORMATION node[MAX];
}STACK;
//---------------------------------- declae these funtion that were used in program.
void InputData(IMFORMATION &data)
{
puts("Hi ! What student's name");
gets(data.Name);
puts("How old is student");
scanf("%d",&data.age);
fflush(stdin);
}
// this funtion use for receive a node
// if stacks don't full
void push(STACK &s)
{
if(s.top == MAX) // check stack is full or not
{ printf("Stack over flow !");
return ;
}
printf("Student nume %d",s.top+2);
InputData(s.node[++s.top]); // set up data student to next node
}
void pop(STACK &s) // Deletion a node
{
if(s.top == -1 ) // check stack is empty or not
{
puts("Stack under flow !");
return ;
}
--s.top;
}
void stacktop(STACK &s)
{
if(s.top == -1 ) // check stack is empty or not
{
puts("Stack under flow !");
return ;
}
printf("Student number %d\n",s.top);
puts(s.node[s.top].Name);
printf("%d\n",s.node[s.top].age);
}
int main(int argc, char* argv[])
{
// to start for stack
STACK s; // make a statement a s variable of STACK struct ;
s.top = -1 ; // top=1 same as stack is empty .
push(s);
stacktop(s);
pop(s);
pop(s);
return 0;
}