您的位置:首页 > 其它

链栈

2015-06-30 16:10 288 查看
//============================================================================

// Name        : C++Study.cpp

// Author      : pan

// Version     :

// Copyright   : Your copyright notice

// Description : Hello World in C++, Ansi-style

//============================================================================

#include <iostream>

#include "Graph.h"

#include <stdio.h>

#include <vector>

#include <cstring>

#include <vector>

#include<stdlib.h>

#include<assert.h>

using namespace std;

#define MAXSIZE 100

struct Stack {
char data;
Stack* next;

};

Stack* pop(Stack* top) {

assert(top!=NULL);
Stack* stack = top;
top = top->next;
delete stack;

return top;

}

Stack* push(Stack* top, char c) {

Stack* stack = new Stack;
stack->data = c;
stack->next = top;
top = stack;
return top;

}

char getpopEle(Stack* top) {

return top->data;

}

void ShowStack(Stack* top) {

Stack* p = top;
while (p != NULL) {
cout << p->data;
p = p->next;
}

}

int main() {

Stack* top = NULL;
char a[] = { 'a', 'b', 'c', 'd' };
for (int i = 0; i < 4; i++) {
top = push(top, a[i]);
}
top = pop(top);
ShowStack(top);
cout<<getpopEle(top);

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: