当前位置:网站首页>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();
}
边栏推荐
- MATLAB求极限
- Bison uses error loop records
- MIT linear algebra Chinese Notes
- Unexpected ‘debugger‘ statement no-debugger
- Gbase8s database into external clause
- qt json
- Quick look | the long-awaited 2022 Guangzhou assistant testing engineer's real problem analysis is finally released
- 面试突击61:说一下MySQL事务隔离级别?
- Syntax of gbase8s database incompatible with for update clause
- 倍福控制器连接松下EtherCAT伺服注意事项
猜你喜欢

Interpolated scatter data

倍福TwinCAT配置、调试第三方伺服详细讲解--以汇川IS620N为例子

Baidu cloud disk downloads large files without speed limit (valid for 2021-11 personal test)

Cocos star meetings at Hangzhou station in 2022

Matlab简单入门

LeetCode_ Double pointer_ Medium_ 328. parity linked list

Interview shock 61: tell me about MySQL transaction isolation level?

多项目开发入门-业务场景关联基础入门测试 工资表
![[cloud native] 2.4 kubernetes core practice (middle)](/img/1e/b1b22caa03d499387e1a47a5f86f25.png)
[cloud native] 2.4 kubernetes core practice (middle)

AES-128-CBC-Pkcs7Padding加密PHP实例
随机推荐
qt json
Gbase8s database select has a having clause
Pangolin compilation error: 'numeric_ limits’ is not a member of ‘std’
Yunlong fire version aircraft battle (full version)
Paper reproduction - ac-fpn:attention-guided context feature pyramid network for object detection
Pygame 精准检测图像碰撞
二十三、1-Bit数据的存储(延迟线/磁芯/DRAM/SRAM/磁带/磁盘/光盘/Flash SSD)
[JUC series] ThreadLocal of synchronization tool class
Gbase8s database for read only clause
NvtBack
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
倍福PLC通过CANOpen通信控制伺服
推荐模型复现(一):熟悉Torch-RecHub框架与使用
Understanding of P value
【JUC系列】同步工具类之ThreadLocal
Uncover the practice of Baidu intelligent test in the field of automatic test execution
Kyligence Zen, an intelligent indicator driven management and decision-making platform, is newly launched and is in limited internal testing
1. opencv realizes simple color recognition
If I am in Shenzhen, where can I open an account? In addition, is it safe to open an account online now?
Gbase8s database select has an order by clause