- 注册时间
- 2004-10-13
- 最后登录
- 2019-5-15
⑧专业
*永恒国度*
- 积分
- 14145
|
- #include<stdio.h>
- #include<stdlib.h>
- struct qnode
- {
- char data;
- struct qnode *next;
-
-
- };
- typedef struct queue
- {
- struct qnode *rear;
- }linkqueue;
- void initqueue(linkqueue *q)
- {
- q=(struct queue *)malloc(sizeof(struct queue));
- q->rear=NULL;
- }
- void enter(linkqueue *q,char x)
- {
- struct qnode *s,*p;
-
- s=(struct qnode *)malloc(sizeof(struct qnode));
- s->data=x;
- if(q->rear==NULL)
- {
- q->rear=s; s->next=s;
- }
- else
- {
- p=q->rear->next;
- q->rear->next=s;
- q->rear=s;s->next=p;
- }
- }
- void del(linkqueue *q)
- {
- struct qnode *t;
- if(q->rear==NULL)
- {
- printf("队列为空\n");
-
- }
- else if(q->rear->next==q->rear)
- {
- t=q->rear;
- q->rear=NULL;
- }
- else
- {
- t=q->rear->next;
- q->rear->next=t->next;
- }
- free(t);
- }
- char gethead(linkqueue *q)
- {
- if(q->rear==NULL)
- printf("队列为空\n");
- else
- return(q->rear->next->data);
- return 0;
- }
- int empty(linkqueue *q)
- {
- if(q->rear==NULL) return 1;
- else return 0;
- }
- void dis(linkqueue *q)
- {
- struct qnode *p=q->rear->next;
- printf("队列元素:");
- while(p!=q->rear)
- {
- printf("%c ",p->data);
- p=p->next;
- }
- printf("%c\n",p->data);
- }
- void main()
- {
-
- linkqueue *qu;
-
- printf("初始化\n");
- initqueue(qu);
- printf("输入a,b,c\n");
- enter(qu,'a');
- enter(qu,'b');
- enter(qu,'c');
- dis(qu);
- }
复制代码 为什么在VC++里无法运行呢?? |
|