标签:lse end iostream 控制 rand app har type 应用
// ConsoleApplication14.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include"stdlib.h" #include"iostream" 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()); dis(p); cout << "*******" << endl; for (int i = 0; i < 10; i++) pop(p); dis(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; }
周六下午晒太阳,喝茶,撸代码
标签:lse end iostream 控制 rand app har type 应用
原文地址:https://www.cnblogs.com/butchert/p/12001461.html