当前位置:网站首页>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();
}
边栏推荐
- huffman编码
- 面试突击61:说一下MySQL事务隔离级别?
- Gbase8s database select has order by Clause 3
- 2022.6.28-----leetcode.324
- Gbase8s database select has an order by clause
- 倍福PLC通过CANOpen通信控制伺服
- Unexpected ‘debugger‘ statement no-debugger
- QT custom control: value range
- 【LeetCode】14、最长公共前缀
- Comment calculer Win / Tai / Loss in paired t - test
猜你喜欢
![[JUC series] ThreadLocal of synchronization tool class](/img/15/2f8ce68b9e5ee8dab03fb688712935.png)
[JUC series] ThreadLocal of synchronization tool class

Principle and process of MySQL master-slave replication

Go learning - build a development environment vscode development environment golang

Qt中的UI文件介绍

推荐模型复现(四):多任务模型ESMM、MMOE

Recurrence of recommended models (IV): multi task models esmm and MMOE

After class assignment of module 5 of the construction practice camp

倍福控制器连接松下EtherCAT伺服注意事项

Unexpected ‘debugger‘ statement no-debugger

Comment calculer Win / Tai / Loss in paired t - test
随机推荐
Pygame 对图像进行翻转
huffman编码
Quick look | the long-awaited 2022 Guangzhou assistant testing engineer's real problem analysis is finally released
qt json
Is it safe for Orient Fortune Securities to open an account? Handling of securities account opening
Viewing splitchunks code segmentation from MPX resource construction optimization
Blurred pictures become clear, one button two-color pictures, quickly organize local pictures These 8 online picture tools apply to join your favorites!
[environment configuration]pwc-net
MySQL master-slave synchronous asynchronous replication semi synchronous replication full synchronous replication
Proteus软件初学笔记
How to install oracle19c in Centos8
Recommended model recurrence (I): familiar with torch rechub framework and use
1. Opencv实现简单颜色识别
二十三、1-Bit数据的存储(延迟线/磁芯/DRAM/SRAM/磁带/磁盘/光盘/Flash SSD)
Kyligence Zen, an intelligent indicator driven management and decision-making platform, is newly launched and is in limited internal testing
MATLAB求极限
C#通过线索二叉树进行中序遍历输出
2022.6.28-----leetcode. three hundred and twenty-four
Inferiority complex and transcendence the meaning of life to you
Nacos startup error