栈来判断链表是否对成
typedef struct
{
char *data;
int top;
} SqStack;
bool isSymmetry(LinkList L){
int len = length(L);
if(len == 0 || len == 1) return true;
SqStack stack;
stack.data = (char*)malloc(sizeof(char) * (len / 2));
stack.top = -1;
LNode *curP = L->next;
for(int i = 0;i < len / 2;i ++)
{
stack.data[ ++ stack.top] = curP->data;
curP = curP->next;
}
if(len % 2 == 1) curP = curP->next;
while(stack.top > -1){
if(stack.data[stack.top] == curP->data){
stack.top --;
curP = curP->next;
}else break;
}
return stack.top == -1;
}
void reverseQueue(SqStack &S,SqQueue &Q){
initStack(S);
ElemType e;
while(!queueEmpty(Q)){
deQueue(Q,e);
push(S,e);
}
while(!stackEmpty(S))
{
pop(S,e);
enQueue(Q,e);
}
}
bool matchBracket(char str[]){
SqStack S;
initStack(S);
char aux,c;
int index = 0;
while((c = str[index ++]) != '\0'){
if(c == '(' || c == '{' || c == '[') push(S,c);
else if(c == ')' || c == ']' || c == '}')
{
if(pop(S,aux) == true)
{
if(!((aux == '(' && c == ')'))
|| (aux == '[' && c == ']')
|| (aux == '{' && c == '}')) return false;
}else return false;
}else return false;
}
return stackEmpty(S);
}
#define MaxSize 100
void dec2hex(){
char *hexR = "0123456789abcdef"
int base = 16;
int stack[MaxSize],top = -1;
do{
stack[++ top] = dex % base;
dec /= base;
}while(dec);
while(top != -1) cout << hexR[stack[top -- ]];
cout << endl;
}
void EnQueue(LinkQueue &Q,Elemtype x){
LinkNode *s = (LinkNode*)malloc(sizeof(LinkNode));
s->data = x;
s->next = NULL;
Q->rear->next = s;
Q->rear = s;
}
bool DeQueue(LinkQueue &Q,Elemtype &X){
if(Q->front == Q.rear){
return false;
}
LinkNode *p = Q->front->next;
x = p->data;
Q.front = p->next;
if(Q.rear = p)
Q.rear = Q.front;
free(p);
return true;
}