using linear list to realize the Stack,code as the following:
// STACK.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<malloc.h>
struct stackpoint{
int data;
stackpoint *next;
} *top=NULL;
int stackin(int data){
stackpoint *h1=(stackpoint *)malloc(sizeof (stackpoint));h1->data=data;
if(top==NULL){top=h1;h1->next=NULL;return 1;}
stackpoint *h2=top;
while(h2->next!=NULL){h2=h2->next;}
h1->next=top;
top=h1;
}
int stackdel(){
stackpoint *h1=top;
top=top->next;
free(h1);
return 1;
}
void stackdply(){
stackpoint *h1=top;
while(h1->next!=NULL){printf("%d\t",h1->data);h1=h1->next;}printf("%d\n",h1->data);
}
int main(int argc, char* argv[])
{ stackin(2);stackin(3);stackin(4);stackin(5);
stackdply();
stackdel();
stackin(9);
stackdply();
stackdel();
stackdply();
return 0;
}
It is useful for me to learn the Data Structure,first simple footmark XD.