printf("删除%d",e);
break;
case 0:
printf("\nexit!\n");
break;
}
printf("\n1.建立一个循环队列\n");
printf("2.求队列长度\n");
printf("3.插入元素\n");
printf("4.删除元素\n");
printf("0.操作结束。\n");
printf("请输入选择:");
scanf("%d",&select);
}
return OK;
}
************************************************************************************************
堆栈
*************************************************************************************************
#include
#include
#define OK 1
#define ERROR 0
#define TURE 1
#define FALSE 0
#define OVERFLOW -2
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
//#define NULL 0;
typedef int Status;
typedef int SElemType;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
//.cpp
#include"h1.h"
Status InitStack(SqStack &S)
{
S.base=(SElemType *)malloc(STACK_INIT_SIZE *sizeof(SElemType));
if(!S.base) exit(OVERFLOW);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
}
Status StackEmpty(SqStack S)
{
if(S.top==S.base)
return OK;
else return ERROR;
}
Status Push(SqStack &S,SElemType e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(SElemType*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType));
if(!S.base) exit(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
return 0;
}
Status Pop(SqStack &S,SElemType &e)
{
if(S.top==S.base) return ERROR;
e=*--S.top;
}
Status Compare()
{
SqStack S;
char ch;
SElemType e;
InitStack(S);
int flag=TURE;
while (((ch= getchar())!='#') && flag )
{
switch (ch) {
case '(' :
case '[' :
case '{' :
Push(S,ch);break;
case ')' :
if ( Pop(S,e)==ERROR || e!='(' )
flag=FALSE;
break;
case ']' :
if ( Pop(S,e)==ERROR || e!='[')
flag=FALSE;
break;
case '}' :
if ( Pop(S,e)==ERROR || e!='{')
flag=FALSE;
break;
}//switch
}
if (flag && ch=='#' && StackEmpty(S))
return TURE;
else return FALSE;
}
Status conversion()
{
SqStack S;
SElemType N,e;
InitStack(S);
printf("输入一个十进制数:");
scanf("%d",&N);
while(N)
{
Push(S,N%16);
N=N/16;
}
while(!StackEmpty(S))
{
Pop(S,e);
if(e<10)
{
printf("%d",e);
}
else
{
switch(e)
{
case 10: printf("A"); break;
case 11: printf("B"); break;
case 12: printf("C"); break;
case 13: printf("D"); break;
case 14: printf("E"); break;
case 15: printf("F"); break;
}
}
}
return OK;
}
void main()
{
int select;
printf("1.进制转换。\