1. 程式人生 > >棧的定義及基本操作

棧的定義及基本操作

#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#define max 50;
typedef struct Tnode
{
	char data;
	struct Tnode *lnode;
	struct Tnode *rnode;
}Tnode;
typedef  Tnode* type;
typedef struct
{
	type data[50];
	int top;
}stack;
void initialstack(stack *s)
{
	s->top = 0;
}
int push(stack *s, type x)
{
	if (s->top == 50)
		return -1;
	s->data[s->top++] = x;
	return 0;
}
type pop(stack *s)
{
	if (s->top == 0)
		exit(-2);
	type x = s->data[--s->top];
	return x;
}
bool isemty(stack *s)
{
	if (s->top == 0)
		return true;
	else
		return false;
}
//3.36