#include<stdio.h> #include<stdlib.h> typedef struct Node *PtrToNode; typedef PtrToNode Stack; struct Node{ int Element; struct Node *Next; }
void Push(int x,Stack s) { PtrToNode p; p = (PtrToNode)malloc(sizeof(struct Node)); if(p==NULL) printf("out of space!\n"); else { p->Element = x; p->Next = s->Next; s->Next = p; } }
int Top(Stack s) { if(s->Next!=NULL) return s->Next->Element; }
void Pop(stack s) { PtrToNode tmp; if(s->Next!=NULL) { tmp = s->Next; s->Next = tmp->Next; free(tmp); } else printf("The stack is empty!\n"); }
原文:http://www.cnblogs.com/avengervirus/p/3812716.html