stack.h

来自「这是我在复习备考软件设计师时,写的一个程序,拓朴排序在很多方面都会very im」· C头文件 代码 · 共 89 行

H
89
字号
#include <cstdio>
#include <iostream>
#include <malloc.h>
using namespace std;
#define type int
/*typedef struct bitnode{
	int data;
	bitnode *lchild;
	bitnode *rchild;
}bitnode;*/
typedef struct stack{
type *base;
type *top;
int size;
}stack;

void initstack(stack &s){
	s.base=(type *)malloc(10*sizeof(type));
//	s.top=s.base;
//	s=new stack;
//	s.base=10*(new int);
	s.size=0;
//	s.next=0;
	s.top=s.base;

}
void push(stack &s,char a){
//	stack p,p1;
//	bitnode *p;
//	p=new bitnode;
	//p=new stack;
//	if(s.top->data) {
		*s.top=a;
//		s.next=new bitnode;
		s.top++;
//		s.top->lchild=p;
//		s.top=p;
		s.size++;
//	}
//	else

}
int Transfer(char n)
{
	if(n=='e') return 0;
	else if(n=='f') return 1;
	else if(n=='g') return 2;
	else if(n=='h') return 3;
	else if(n=='i') return 4;
	else if(n=='a') return 5;
	else if(n=='b') return 6;
	else if(n=='c') return 7;
	else  return 8;
//	else if(n=='d')
}

type pop(stack &s,type &b){
//	bitnode *p;
//	p->lchild=new bitnode;
	char c;
	s.top--;
	c=*s.top;
//	b=p;
	b=Transfer(c);
	s.size--;
	return b;
}
int stackempty(stack &s){
	return s.top==s.base;
}

/*void main()
{
	stack s;
	initstack(s);
	push(s,1);
	push(s,3);
	printf("%d  ",pop(s));
	push(s,4);
	push(s,5);
	printf("%d  ",pop(s));
	push(s,6);
	printf("%d  ",pop(s));
	while(!stackempty(s))
		printf("%d  ",pop(s));
}*/


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?