user-0 提问: 编写一个链队列任意输出一串字符，以#作为结束标志，然后将对列串中的元素显示到屏幕上

回复:
user: user-1

user: user-0
content: 谢谢大家,万分感谢

user: user-2
content: 仅供参考//带表头结点的单向链表 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <time.h> struct NODE {     int          data;     struct NODE *next; } H,*head,*p,*q,*s1,*s2,*s3,*s4,*s; int i,j,k,n,t,m; int main() {     srand(time(NULL));      //填写头节点数据     H.data=-1;     H.next=NULL;     head=&H;      //创建10个节点的单链表     p=head;     for (i=0;i<10;i++) {         q=(struct NODE *)malloc(sizeof(struct NODE));         if (NULL==q) return 1;         q->data=rand()%100;//填写0..99的随机值         q->next=NULL;         p->next=q;         p=q;     }      //输出整个单链表     s=head->next;     while (1) {         if (NULL==s) {             printf("\n");             break;         }         printf("%02d->",s->data);         s=s->next;     }      //将值为5的结点插入到单链表的第k个结点前     k=3;     n=0;     p=head;     while (1) {         if (NULL==p) {             break;         }         n++;         if (k==n) {             q=(struct NODE *)malloc(sizeof(struct NODE));             if (NULL==q) return 1;             q->data=5;             q->next=p->next;             p->next=q;             break;         }         p=p->next;     }      //输出整个单链表     s=head->next;     while (1) {         if (NULL==s) {             printf("\n");             break;         }         printf("%02d->",s->data);         s=s->next;     }      //删除第k个节点     k=5;     n=0;     p=head;     while (1) {         if (NULL==p) {             break;         }         n++;         if (k==n) {             q=p->next;             if (q) {                 p->next=q->next;                 free(q);             }             break;         }         p=p->next;     }      //输出整个单链表     s=head->next;     while (1) {         if (NULL==s) {             printf("\n");             break;         }         printf("%02d->",s->data);         s=s->next;     }      //从小到大排序     for (p=head;p!=NULL && p->next!=NULL;p=p->next) {         for (q=p->next;q!=NULL && q->next!=NULL;q=q->next) {             if (p->next->data > q->next->data) {                  //交换data //              printf("swap %02d %02d\n",p->next->data,q->next->data); //              t=p->next->data;p->next->data=q->next->data;q->next->data=t;                  //或者                  //交换next //              printf("swap %02d %02d\n",p->next->data,q->next->data);                 s1=p->next;                 s2=p->next->next;                 s3=q->next;                 s4=q->next->next;                  if (s2!=s3) {                      p->next=s3;                     s3->next=s2;                      q->next=s1;                     s1->next=s4;                 } else {                      p->next=s3;                     s3->next=s1;                            q=s3;                     s1->next=s4;                 }                  //输出整个单链表 //              s=head->next; //              while (1) { //                  if (NULL==s) { //                      printf("\n"); //                      break; //                  } //                  printf("%02d->",s->data); //                  s=s->next; //              } //              getchar();             }         }     }      //输出整个单链表     s=head->next;     while (1) {         if (NULL==s) {             printf("\n");             break;         }         printf("%02d->",s->data);         s=s->next;     }      //将单链表中前 m 个结点和后 n 个结点进行互换,m+n为链表总长10     m=4;     n=6;     k=0;     p=head;     while (1) {         if (NULL==p) {             break;         }         k++;         if (m+1==k) {             q=p;         }         s=p;         p=p->next;     }     s1=head->next;     head->next=q->next;     s->next=s1;     q->next=NULL;      //输出整个单链表     s=head->next;     while (1) {         if (NULL==s) {             printf("\n");             break;         }         printf("%02d->",s->data);         s=s->next;     }      //释放所有节点     p=head->next;     while (1) {         if (NULL==p) {             break;         }         q=p->next;         free(p);         p=q;     }      return 0; } //18->94->58->17->27->20->43->57->75->78-> //18->94->05->58->17->27->20->43->57->75->78-> //18->94->05->58->27->20->43->57->75->78-> //05->18->20->27->43->57->58->75->78->94-> //43->57->58->75->78->94->05->18->20->27-> //

user: user-3
content: #include <stdio.h> #include <stdlib.h> #include <string.h>  typedef char ElemType;  struct QNode { 	ElemType data; 	struct QNode *next; };  struct LinkQueue { 	struct QNode* front; 	struct QNode* rear; };  int initQueue(LinkQueue *q) { 	q->front = q->rear = (QNode*) malloc(sizeof(QNode));  	if (!q->front) { 		return 0; 	} 	q->front->next = NULL;  	return 1;  }  int InsertQueue(LinkQueue *q, ElemType e) { 	struct QNode *p;  	p = (QNode*) malloc(sizeof(QNode));  	if (p == NULL) { 		return 0; 	} 	p->data = e; 	p->next = NULL; 	q->rear->next = p; 	q->rear = p;  	return 1;  }  int PrintQueue(LinkQueue *q) {  	QNode *now = q->front->next;  	while (now) {  		printf("%c", now->data);  		now = now->next;  	}  	return 1; }  int DeleteQueue(LinkQueue *q) {  	QNode *now = q->front;  	while (now) {  		QNode *temp = now->next;  		free(now);  		now = temp; 	}  	return 1; }  int main() {  	LinkQueue s; 	ElemType c;  	initQueue(&s);  	printf("输出任意一串字符，以#作为结束标志\n");  	scanf("%c", &c);  	while (c != '#') {  		InsertQueue(&s, c); 		scanf("%c", &c); 	}  	printf("\n");  	PrintQueue(&s);  	DeleteQueue(&s);  	return 0; }