void remove_stack(Stack *stack) { StackNode sn; while(!isEmpty_stack(stack)) { sn = pop(stack); print_stack_node(&sn); } }
StackNode pop(Stack *stack) { StackNode res; res.data = dummy_data; res.isChar = FALSE; if(!stack || isEmpty_stack(stack)) return res; res = *(stack->topNode); StackNode *tmp = stack->topNode; stack->topNode = tmp->pNode; free(tmp); return res; }
void DFS(int v) { int i; push(v); while(!isEmpty_stack()) { v = pop(); if(state[v]==initial) { printf("%d ",v); state[v]=visited; } for(i=n-1; i>=0; i--) { if(adj[v][i]==1 && state[i]==initial) push(i); } } }/*End of DFS( )*/
void reverse_by_stack(LinkList L) { LinkList q = L->next; SqStack s; InitStack(&s); while(q) { Push(&s,q->data); LinkList temp = q; q = q->next; free(temp); } q = L; while(!isEmpty_stack(s)) { Node *p = (Node *)malloc(sizeof(Node)); p->data = Pop(&s); q->next = p;//连接到尾部 q = q->next; } q->next = NULL; }