网站做301怎么做杭州游戏软件开发公司
web/
2025/10/4 16:47:08/
文章来源:
网站做301怎么做,杭州游戏软件开发公司,网站建设考评办法,折扣网站搭建数据结构#xff08;三#xff09;队列队列队列#xff08;顺序存储#xff09;循环队列#xff08;顺序存储#xff09;队列#xff08;链式存储#xff09;队列
队列是一种受限制的线性表#xff0c;只允许表的一端插入#xff0c;在表的另一端删除
队列#xf…
数据结构三队列队列队列顺序存储循环队列顺序存储队列链式存储队列
队列是一种受限制的线性表只允许表的一端插入在表的另一端删除
队列顺序存储
// linear_Queue.cpp : This file contains the main function. Program execution begins and ends there.
//#include iostream
#include stdio.h
#include stdlib.h
using namespace std;#define maxsize 50
#define elemtype int
typedef struct
{elemtype data[maxsize];int front, rear; //队头指针和队尾指针
}SqQueue;void InitQueue(SqQueue Q)
{Q.rear Q.front 0; //初始化队首、队尾指针
}bool QueueEmpty(SqQueue Q)
{if (Q.front Q.rear){return true;}return false;
}bool EnQueue(SqQueue Q, elemtype x)
{if (Q.rear maxsize){return false;}Q.data[Q.rear] x;//添加队列return true;
}elemtype DeQueue(SqQueue Q)
{bool retQueueEmpty(Q);if (ret){printf(队列为空!\n);exit(1);}return Q.data[Q.front];//添加队列
}bool GetHead(SqQueue Q, elemtype x)
{if (QueueEmpty(Q)){printf(队列为空!\n);exit(1);}x Q.data[Q.front];return true;
}int main()
{SqQueue Q;InitQueue(Q);EnQueue(Q, 5);EnQueue(Q, 8);EnQueue(Q, 10);DeQueue(Q);for (int i Q.front; i Q.rear; i){printf(%d\n,Q.data[i]);}}// Run program: Ctrl F5 or Debug Start Without Debugging menu
// Debug program: F5 or Debug Start Debugging menu// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project Add New Item to create new code files, or Project Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File Open Project and select the .sln file
循环队列顺序存储
// linear_Queue.cpp : This file contains the main function. Program execution begins and ends there.
//#include iostream
#include stdio.h
#include stdlib.h
using namespace std;#define maxsize 50
#define elemtype int
typedef struct
{elemtype data[maxsize];int front, rear; //队头指针和队尾指针
}SqQueue;void InitQueue(SqQueue Q)
{Q.rear Q.front 0; //初始化队首、队尾指针
}bool QueueEmpty(SqQueue Q)
{if (Q.front Q.rear){return true;}return false;
}bool EnQueue(SqQueue Q, elemtype x)
{if (Q.rear maxsize){return false;}Q.data[Q.rear] x;//添加队列return true;
}elemtype DeQueue(SqQueue Q)
{bool retQueueEmpty(Q);if (ret){printf(队列为空!\n);exit(1);}return Q.data[Q.front];//添加队列
}bool GetHead(SqQueue Q, elemtype x)
{if (QueueEmpty(Q)){printf(队列为空!\n);exit(1);}x Q.data[Q.front];return true;
}int main()
{SqQueue Q;InitQueue(Q);EnQueue(Q, 5);EnQueue(Q, 8);EnQueue(Q, 10);DeQueue(Q);for (int i Q.front; i Q.rear; i){printf(%d\n,Q.data[i]);}}// Run program: Ctrl F5 or Debug Start Without Debugging menu
// Debug program: F5 or Debug Start Debugging menu// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project Add New Item to create new code files, or Project Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File Open Project and select the .sln file
队列链式存储
带头结点
// linear_listqueue.cpp : This file contains the main function. Program execution begins and ends there.
//#include iostream
#include stdlib.h
#include stdio.h
#define ElemType int
using namespace std;typedef struct linknode //链式节点
{ElemType data;struct linknode* next;}LinkNode;//链式队列
typedef struct
{LinkNode* front, *rear;}LinkQueue;void InitQueue(LinkQueue Q)
{//带头节点的队列初始化Q.rearQ.front(LinkNode*)malloc(sizeof(LinkNode));Q.front-next NULL;
}bool IsEmpty(LinkQueue Q)
{if (Q.rear Q.front){return true;}return false;}void EnQueue(LinkQueue Q, ElemType x)
{LinkNode* s (LinkNode*)malloc(sizeof(LinkNode));s-data x;s-next Q.rear-next;Q.rear-next s;Q.rear s;}bool DeQueue(LinkQueue Q, ElemType x)
{if (IsEmpty(Q)){//队列为空return false;}LinkNode* p Q.front-next;x p-data;Q.front-next p-next;if (p Q.rear) //要删除的为尾队列{Q.rear Q.front;}free(p);return true;
}int main()
{int x;LinkQueue Q;InitQueue(Q);EnQueue(Q, 5);EnQueue(Q, 7);EnQueue(Q, 9);DeQueue(Q, x);LinkNode* p Q.front-next;while (p ! NULL){printf(%d\n,p-data);p p-next;}}// Run program: Ctrl F5 or Debug Start Without Debugging menu
// Debug program: F5 or Debug Start Debugging menu// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project Add New Item to create new code files, or Project Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File Open Project and select the .sln file
不带头结点
// linear_listqueue.cpp : This file contains the main function. Program execution begins and ends there.
//#include iostream
#include stdlib.h
#include stdio.h
#define ElemType int
using namespace std;typedef struct linknode //链式节点
{ElemType data;struct linknode* next;}LinkNode;//链式队列
typedef struct
{LinkNode* front, * rear;}LinkQueue;void InitQueue(LinkQueue Q)
{//不带头节点的队列初始化Q.front Q.rear NULL;
}bool IsEmpty(LinkQueue Q)
{if (Q.rear Q.front){return true;}return false;}void EnQueue(LinkQueue Q, ElemType x)
{LinkNode* s (LinkNode*)malloc(sizeof(LinkNode));if(Q.frontNULL){s-data x;s-next NULL;Q.front Q.rear s;return;}s-next NULL;s-data x;Q.rear-next s;Q.rear s;}bool DeQueue(LinkQueue Q, ElemType x)
{if (IsEmpty(Q)){printf(Queue is empty!\n);//队列为空return false;}LinkNode* p Q.front-next;free(Q.front);Q.front p;
}int main()
{int x;LinkQueue Q;InitQueue(Q);EnQueue(Q, 5);EnQueue(Q, 7);EnQueue(Q, 9);DeQueue(Q, x);LinkNode* p Q.front;while (p ! NULL){printf(%d\n, p-data);p p-next;}}// Run program: Ctrl F5 or Debug Start Without Debugging menu
// Debug program: F5 or Debug Start Debugging menu// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project Add New Item to create new code files, or Project Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File Open Project and select the .sln file
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/86873.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!