当前位置:网站首页>C # implements queue structure definition, incoming and outgoing operations
C # implements queue structure definition, incoming and outgoing operations
2022-06-29 12:53:00 【Dusk and starry sky】
In this paper, C# Implement queue structure definition 、 The team 、 Out of line operation
1、 Queue structure definition
///
/// Queue structure definition
///
public struct SqQueue {
public int[] data;// Queued elements
public int front, real;// Team leader and team leader
}
2、 Queue initialization
///
/// Queue initialization
///
///
static void InitQueue(ref SqQueue Q) {
Q.real = Q.front=0;
}
3、 Determines if the queue is empty
///
/// Determines if the queue is empty
///
///
///
static bool isEmpty( SqQueue Q) {
if (Q.front == Q.real) { return true; }
else return false;
}
4、 The team
///
/// The team
///
///
///
///
static bool EnQueue(ref SqQueue Q,int x) {
if ((Q.real+1)%MAXSizeQ.front) { return false; }
Q.data[Q.real] = x;
Q.real = (Q.real + 1) % MAXSize;
return true;
}
5、 Out of the team
static bool DeQueue(ref SqQueue Q, ref int x) {
if (Q.realQ.front) { return false; }
x = Q.data[Q.front];
Q.front = (Q.front + 1) % MAXSize;
return true;
}
6、 actual main Function test
static void Main(string[] args)
{
SqQueue Q = new SqQueue();
Q.data = new int[MAXSize];
int x = 0;
// Initialize queue
InitQueue(ref Q);
while (x!=999) {
Console.WriteLine(“ Please enter the team entry element :”);
x = int.Parse(Console.ReadLine());
if ((Q.real+1)%MAXSize==Q.front) {
Console.WriteLine(“ The queue is full .”);
break;
}
if (x!=999) EnQueue(ref Q, x);
}
// Out of the team
Console.WriteLine(“ The output elements are as follows :”);
while (!isEmpty(Q)) {
DeQueue(ref Q,ref x);
Console.WriteLine(x);
}
Console.ReadLine();
}
边栏推荐
- 百度云盘不限速下载大文件(2021-11亲测有效)
- QT custom control: value range
- oracle 19c : change the user sys/system username pasword under Linux
- 2022.6.28-----leetcode.324
- C#通過中序遍曆對二叉樹進行線索化
- 【LeetCode】14、最长公共前缀
- Adjacency matrix and adjacency table structure of C # realization graph
- Can software related inventions be patented in India?
- Recurrence of recommended models (III): recall models youtubednn and DSSM
- 解决问题:ModuleNotFoundError: No module named ‘pip‘
猜你喜欢

在印度与软件相关的发明可不可以申请专利?

Principle and process of MySQL master-slave replication

AGCO AI frontier promotion (6.29)

Problem solving: modulenotfounderror: no module named 'pip‘

【LeetCode】14、最长公共前缀

Go learning - build a development environment vscode development environment golang

Qt的信号与槽

Qt中的UI文件介绍

Understanding of P value

Unexpected ‘debugger‘ statement no-debugger
随机推荐
huffman编码
Proteus软件初学笔记
asp.net 项目使用aspnet_compiler.exe发布
InDesign插件-常规功能开发-JS调试器打开和关闭-js脚本开发-ID插件
nvtmpp
LeetCode_ Double pointer_ Medium_ 328. parity linked list
倍福控制第三方伺服走CSV模式--以汇川伺服为例
cmake 报错
C # output the middle order traversal through the clue binary tree
如果我在深圳,到哪里开户比较好?另外想问,现在在线开户安全么?
Huffman coding
云龙开炮版飞机大战(完整版)
Gbase8s database select has order by Clause 6
[leetcode] 14. Longest public prefix
Gbase8s database select has order by Clause 3
Interview shock 61: tell me about MySQL transaction isolation level?
Gbase8s database select has order by Clause 6
面试突击61:说一下MySQL事务隔离级别?
【君正T31】只读rootfs文件系统squashfs的解压和打包
Gbase8s database select has order by Clause 1