C语言数据结构之链式队列(链表实现方式)
1、【1】打开Visual Studio 2013软件并创建Win32控制台应用程序。【2】添加后文件#include "stdafx.h"#include "stdio.h"#include "malloc.h"#include "stdbool.h"【3】验证刚创建工程的完整性和正确性#include "stdafx.h"#include "stdio.h"#include "malloc.h"#include "stdbool.h"void main(void){ printf("Hello World......\r\n"); while (1);}






3、【1】编写链式队列数据入队函数为新入队的结点分配内存、将新入队结点挂到队尾指针上,队尾指针指向新入队结点。//链式队列数据入队void EnterLinkQueue(pLinkQueue queue, int value){ pNode newNode = NULL;//链式队列入队结点指针 //为链式队列入队结点申请内存 newNode = (Node *)malloc(sizeof(Node)); if (newNode == NULL) { printf("链式队列入队结点内存申请失败......\r\n"); return; } queue->qRear->pNext = newNode;//入队新结点为最后个结点 queue->qRear = newNode;//队尾指向入队新结点 newNode->pNext = NULL;//入队新结点无下个结点 newNode->dat = value;//入队值 printf("入队成功!入队值:%d ----> ", value); printf("队首结点指针:0x%08X 队尾指针:0x%08X\r\n", queue->qFront, queue->qRear);}【2】验证链式队列数据入队void main(void){ pLinkQueue Queue; Queue = CreatLinkQueue();//创建链式队列 printf("\r\n"); EnterLinkQueue(Queue, 10);//链式队列数据入队 EnterLinkQueue(Queue, 20); EnterLinkQueue(Queue, 30); while (1);}【3】编写遍历链式队列数据函数//遍历链式队列数据void TraverseLinkQueue(pLinkQueue queue){ pNode queNode = NULL;//结点指针 if (IsEmptyLinkQueue(queue)) { printf("链式队列为空,遍历失败......\r\n"); return; } printf("链式队列数据: "); queNode = queue->qFront->pNext;//第一个有效结点 while (queNode != NULL)//最后一个结点结束 { printf("%d ", queNode->dat);//结点数据 queNode = queNode->pNext;//下一个结点 } printf("\r\n");}【4】验证遍历链式队列数据void main(void){ pLinkQueue Queue; Queue = CreatLinkQueue();//创建链式队列 printf("\r\n"); EnterLinkQueue(Queue, 10);//链式队列数据入队 EnterLinkQueue(Queue, 20); EnterLinkQueue(Queue, 30); TraverseLinkQueue(Queue);//遍历链式队列数据 printf("\r\n"); while (1);}








