user-0 提问: C程序填空  关于栈和队列的基本操作  求详细解释！！！！ 

回复:
user: user-0
content: 我想问一下 linklist *creatlist() {     linklist *p,*q;     int n=0;      q = p = (struct node *)malloc(sizeof(linklist));     head = p;     p->next = NULL;     p = (struct node *)malloc(sizeof(linklist));     scanf("%d", &p->data);     while(p->data!=-1)     {         n = n+1;         q->next = p;         q = p;         p = (struct node *)malloc(sizeof(linklist));         scanf("%d", &p->data);     }     q->next = NULL;      return(head); } 里面的int n 有什么用嘛？每次循环还要n+1?

user: user-1
content: gdb调试，

user: user-2
content: 代码功能归根结底不是别人帮自己看或讲解或注释出来的；而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。 提醒：再牛×的老师也无法代替学生自己领悟和上厕所！ 单步调试和设断点调试（VS IDE中编译连接通过以后，按F10或F11键单步执行，按Shift+F11退出当前函数；在某行按F9设断点后按F5执行停在该断点处。）是程序员必须掌握的技能之一。

user: user-3
content: #include<stdio.h> #include<stdlib.h> #include<malloc.h>  typedef int SElemType;  typedef struct node {     int  data;     struct node *next; }linklist;  linklist *head;  #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10  typedef struct  {     SElemType       *base;     SElemType       *top;     int     stacksize; } SeqStack;  SeqStack *S;  linklist *creatlist() {     linklist *p,*q;     int n=0;      q = p = (struct node *)malloc(sizeof(linklist));     head = p;     p->next = NULL;     p = (struct node *)malloc(sizeof(linklist));     scanf("%d", &p->data);     while(p->data!=-1)     {         n = n+1;         q->next = p;         q = p;         p = (struct node *)malloc(sizeof(linklist));         scanf("%d", &p->data);     }     q->next = NULL;      return(head); }  void print(linklist *head) {     linklist *p;      p = head->next;     if(p==NULL)  {         printf("this is an empty list.\n");         return;     }         do {             printf("%6d",p->data);             p = p->next;         }while(p);          printf("\n"); }   int InitStack(SeqStack **S ) {     *S = (SeqStack *)malloc(sizeof(SeqStack));     if (!(*S))         return 0;      (*S)->base = (SElemType*)malloc(STACK_INIT_SIZE * sizeof(SElemType));     if ((*S)->base == NULL)         return 0;     (*S)->top = (*S)->base;     (*S)->stacksize = STACK_INIT_SIZE;      return 1; }  int push(SeqStack *S,SElemType e) {     if(S->top - S->base >= S->stacksize)     {         S->base = (SElemType *)realloc(S->base,                 (S->stacksize + STACKINCREMENT)*sizeof   (SElemType));         if (!S->base )             return 0;         S->top = S->base + S->stacksize;         S->stacksize += STACKINCREMENT;     }      *(S->top++) = e;      return 1; }    int Pop (SeqStack *S ) {      if(S->top == S->base)         return 0;      S->top--;     return  *S->top ; }   int stackempty(SeqStack *S) {     if (S->top == S->base)         return 1;     else return 0; }    linklist *backlinklist(linklist *head) {     linklist *p;     p = head->next;     InitStack (&S);      while(p)     {         if( push(S, p->data));         p = p->next;     }     p = head->next;      while(!stackempty(S))     {          p->data = Pop(S);         p = p->next;     }     return(head); }  int main() {     linklist *head;     head=creatlist();     print(head);     head = backlinklist(head);     print(head);      return 0; }  参考一下吧