// ConsoleApplication14.cpp: custom console application entry point. // #include " stdafx.h " #include " stdlib.h " #include " iostream " a using namespace std; #define MAX 100 typedef int data; typedef struct { int top; data a[MAX]; }st; void init(st *p); void push(st *p, data x); void pop(st *p); void dis(st *p); int _tmain(int argc, _TCHAR* argv[]) { st ss, *p; p = &ss; init(p); for (int i = 0; i < 10; i++) push(p, rand()); RO (p); cout << "*******" << endl; for (int i = 0; i < 10; i++) pop(p); RO (p); return 0; } void init(st *p) { p->top = 0; } void push(st *p, data x) { if (p->top >= MAX) cout << "It is full!" << endl; else { p->a[p->top] = x; p->top++; } } void pop(st *p) { if (p->top == 0) cout << "It is empty!" << endl; else p->top--; } void dis(st *p) { for (int i = 0; i < p->top; i++) cout << p->a[i] << endl; }
Saturday afternoon in the sun, drinking tea, roll up the code