C语言求程序：顺序循环队列的实现和相关操作

1个回答

#include

#include

#define OK 1

#define ERROR 0

#define QUEUE_SIZE 100

typedef int Status;

typedef int ElemType;

typedef struct Qnode

{

ElemType base;

int front;

int rear;

int count;

} Qnode;

Status Init(Qnode &qq)

{

qq.base = (ElemType
)malloc(QUEUE_SIZE * sizeof(ElemType));

if (qq.base == NULL) return ERROR;

qq.front = 0;

qq.rear = 0;

qq.count = 0;

return OK;

}

Status EnQueue(Qnode &qq, ElemType e)

{

``````   if ((qq.rear + 1) % QUEUE_SIZE == qq.front)
return ERROR;
qq.base[qq.rear] = e;
qq.rear = (qq.rear + 1)%QUEUE_SIZE;
qq.count++;
return OK;
``````

}

Status DeQueue(Qnode &qq, ElemType &e)

{

if (qq.rear == qq.front)

return ERROR;

e = qq.base[qq.front];

qq.front = (qq.front + 1) % QUEUE_SIZE;

qq.count--;

return OK;

}

Status GetTop(Qnode &qq, ElemType &e)

{

if (qq.rear == qq.front)

return ERROR;

e = qq.base[qq.front];

return OK;

}

Staus Destroy(Qnode qq)

{

free(qq.base);

qq.base = NULL;

qq.count = 0;

return OK;

}

int main()

{

Qnode qq;

Init(qq);

int m, i;

printf("how many nums?\n");

scanf("%d", &m);

for (i = 0; i < m; i++)

{

int e;

scanf("%d", &e);

EnQueue(qq, e);

}

int e;

GetTop(qq, e);

printf("%d\n" , e);

for (i = 0; i < m; i++)

{

DeQueue(qq, e);

printf("%d ", e);

}

printf("\n");

system ("pause");

return 0;

} C语言 数据结构 三、 创建一个字符循环队列，实现字符元素入队列、出队列、显示队列元素等操作。要求为用户提供选择式菜单

c语言消息队列如何实现滑动窗口

Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always be 1. Input n (0 < n < 20). Output The output format is shown as sample below. Each row represents a series of circle numbers in the ring beginning from 1 clockwisely and anticlockwisely. The order of numbers must satisfy the above requirements. Print solutions in lexicographical order. You are to write a program that completes above process. Print a blank line after each case. Sample Input 6 8 Sample Output Case 1: 1 4 3 2 5 6 1 6 5 2 3 4 Case 2: 1 2 3 8 5 6 7 4 1 2 5 8 3 4 7 6 1 4 7 6 5 8 3 2 1 6 7 4 3 8 5 2

1．实现队列的接口： public interface IQueue { public void clear();//将队列置空 public boolean isEmpty();//判断队列是否为空 public int length();//返回队列的数据元素个数 public Object peek();//返回队首元素 //将数据元素x插入到队列成为队尾元素 public void offer(Object x) throws Exception; public Object poll();//将队首元素删除并返回其值 public void display();//输出队列中的所有数据元素 } a.完成基于顺序存储的顺序队列。 b.在顺序队列的基础上完成基于顺序存储的循环顺序队列。 c.完成基于链式存储的链队列。 d.在链队列的基础上完成基于链式存储的优先级队列。 并进行入队，出队等相应功能测试。

Problem Description The Swedish company SKF makes ball bearings. As explained by Britannica Online, a ball bearing is “one of the two types of rolling, or anti friction, bearings (the other is the roller bearing). Its function is to connect two machine members that move relative to one another so that the frictional resistance to motion is minimal. In many applications, one of the members is a rotating shaft and the other a fixed housing. Each ball bearing has three main parts: two grooved, ring like races and a number of balls. The balls fill the space between the two races and roll with negligible friction in the grooves. The balls may be loosely restrained and separated by means of a retainer or cage.” Presumably, the more balls you have inside the outer ring, the smoother the ride will be, but how many can you t within the outer ring? You will be given the inner diameter of the outer ring, the diameter of the balls, and the minimum distance between neighboring balls. Your task is to compute the maximum number of balls that will t on the inside of the outer ring (all balls must touch the outer ring). Input The first line of input contains a positive integer n that indicates the number of test cases. Then follow n lines, each describing a test case. Each test case consists of three positive oating point numbers, D, d, s, where D is the inner diameter of the outer ring, d is the diameter of a ball, and s is the minimum distance between balls. All parameters are in the range [0.0001, 500.0]. Output For each test case output a single integer m on a line by itself, where m is the maximum number of balls that can t in the ball bearing, given the above constraints. There will always be room for at least three balls. Sample Input 2 20 1 0.1 100.0 13.0 0.2 Sample Output 54 20

Problem Description After the 32nd ACM/ICPC regional contest, Wiskey is beginning to prepare for CET-6. He has an English words table and read it every morning. One day, Wiskey's chum wants to play a joke on him. He rolling the table, and tell Wiskey how many time he rotated. Rotate 90 degrees clockwise or count-clockwise each time. The table has n*n grids. Your task is tell Wiskey the final status of the table. Input Each line will contain two number. The first is postive integer n (0 < n <= 10). The seconed is signed 32-bit integer m. if m is postive, it represent rotate clockwise m times, else it represent rotate count-clockwise -m times. Following n lines. Every line contain n characters. Output Output the n*n grids of the final status. Sample Input 3 2 123 456 789 3 -1 123 456 789 Sample Output 987 654 321 369 258 147

lua 实现循环队列 一定长度的

c++求循环队列的元素个数
int getSize( )const {return (rear-front+maxsize)%maxsize;} 函数体返回的为什么不是rear-front?两者有啥区别吗？

（修改报错的程序）线性表及栈与队列的实现 -- 栈
1.问题描述： 针对线性表或栈或队列（三者任选一种逻辑结构），按要求完成类（模板）的实现，并使用提供的main函数测试程序。 2.完成时有几种选择： a.栈的实现。 b. 队列的实现。 c. 线性表的实现。 这里是栈的实现。务必按照提供的代码为基础进行补充。 #include<iostream> #include<cstdlib> using namespace std; #define MAX 100 template <typename T> class Stack { public: Stack(); //构造函数 bool empty() const ; //判断S是否为空栈 bool full() const; //判断栈S是否为满， ~Stack(); //将栈S清空 int size() const; //求栈S的长度，即栈S中的元素的个数 T & top() const; //返回栈S的栈顶元素 void push( const T &e ); //入栈操作，将数据元素e插入栈S的当前栈顶 T & pop(); //出栈操作，删除栈S的栈顶元素，并返回其值 private: // 补充 T data[MAX]; int cur; }; template <typename T> Stack<T>::Stack() { cur = 0; } template<typename T> bool Stack<T>::empty() const { cur = 0; } template<typename T> bool Stack<T>::full() const { return cur >= MAX; } template<typename T> Stack<T>::~Stack() {} template<typename T> int Stack<T>::size() const { return cur; } template<typename T> T & Stack<T>::top() const { if (cur == 0) throw "stack is empty"; return data[cur - 1]; } template<typename T> void Stack<T>::push( const T &e ) { if (cur >= MAX) throw "stack is full"; data[cur++] = e; } template<typename T> T & Stack<T>::pop() { if (cur == 0) throw "stack is empty"; return data[--cur]; } //测试的main函数 int main() { Stack<char> sc; //stack of char Stack<int> si; //Stack of int char ch = ' '; // 不断输入字符到栈中，=结束 while (ch != '=') { cin >> ch; if (ch == 'a') sc.push('A'); sc.push(ch); } cout << "top=" << sc.top() << "size=" << sc.size() << endl; cout << "pop " << sc.pop() << endl; while (!sc.empty()) cout << sc.pop()<< " "; cout << endl; int x = 1; // 不断输入int到栈中，0结束 while (x != 0) { cin >> x; if (x > 10) si.push(10000); si.push(x); } cout << "top=" << si.top() << "size=" << si.size() << endl; cout << "pop " << si.pop() << endl; while (!si.empty()) cout << si.pop()<< "/"; cout << endl; return 0; } 这个程序报错 return data[cur - 1];这一行显示错误，怎么修改？？？

Problem Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1...K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds: 1 5 3 2 5 1 3 4 4 2 5 1 2 3 Farmer John's acute mathematical mind notices all sorts of properties of number sequences like that above. For instance, he notices that the sequence 3 4 1 3 is a subsequence (not necessarily contiguous) of the sequence of breed IDs above. FJ is curious what is the length of the shortest possible sequence he can construct out of numbers in the range 1..K that is NOT a subsequence of the breed IDs of his cows. Help him solve this problem. Input * Line 1: Two integers, N and K * Lines 2..N+1: Each line contains a single integer that is the breed ID of a cow. Line 2 describes cow 1; line 3 describes cow 2; and so on. Output * Line 1: The length of the shortest sequence that is not a subsequence of the input Sample Input 14 5 1 5 3 2 5 1 3 4 4 2 5 1 2 3 Sample Output 3
Java学习的正确打开方式

linux系列之常用运维命令整理笔录

Vue + Spring Boot 项目实战（十四）：用户认证方案与完善的访问拦截

Python十大装B语法
Python 是一种代表简单思想的语言，其语法相对简单，很容易上手。不过，如果就此小视 Python 语法的精妙和深邃，那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点，并附上详细的实例代码。如能在实战中融会贯通、灵活使用，必将使代码更为精炼、高效，同时也会极大提升代码B格，使之看上去更老练，读起来更优雅。 1. for - else 什么？不是 if 和 else 才

2019年11月中国大陆编程语言排行榜
2019年11月2日，我统计了某招聘网站，获得有效程序员招聘数据9万条。针对招聘信息，提取编程语言关键字，并统计如下： 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7

SQL-小白最佳入门sql查询一

“狗屁不通文章生成器”登顶GitHub热榜，分分钟写出万字形式主义大作

IT界知名的程序员曾说：对于那些月薪三万以下，自称IT工程师的码农们，其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居，但只是他们一厢情愿罢了。 此话一出，不知激起了多少(码农)程序员的愤怒，却又无可奈何，于是码农问程序员。 码农：你知道get和post请求到底有什么区别？ 程序员：你看这篇就知道了。 码农：你月薪三万了？ 程序员：嗯。 码农：你是怎么做到的? 程序员：
《程序人生》系列-这个程序员只用了20行代码就拿了冠军

11月8日，由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办，科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。 　　区块链技术被认为是继蒸汽机、电力、互联网之后，下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力，电力解决了人类基本的生活需求，互联网彻底改变了信息传递的方式，区块链作为构造信任的技术有重要的价值。 　　1

Android 9.0系统新特性，对刘海屏设备进行适配

【技巧总结】位运算装逼指南

8年经验面试官详解 Java 面试秘诀
作者 | 胡书敏 责编 | 刘静 出品 | CSDN（ID：CSDNnews） 本人目前在一家知名外企担任架构师，而且最近八年来，在多家外企和互联网公司担任Java技术面试官，前后累计面试了有两三百位候选人。在本文里，就将结合本人的面试经验，针对Java初学者、Java初级开发和Java开发，给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实

1.两种思维方式在求职面试中，经常会考察这种问题：北京有多少量特斯拉汽车？ 某胡同口的煎饼摊一年能卖出多少个煎饼？ 深圳有多少个产品经理？ 一辆公交车里能装下多少个乒乓球？ 一
{"ft_lang_label":"__label__zh","ft_lang_prob":0.7554839,"math_prob":0.9767978,"size":16423,"snap":"2019-51-2020-05","text_gpt3_token_len":10280,"char_repetition_ratio":0.06918813,"word_repetition_ratio":0.04870466,"special_character_ratio":0.2632893,"punctuation_ratio":0.14028645,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9628683,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-24T08:55:48Z\",\"WARC-Record-ID\":\"<urn:uuid:afcd95d1-980d-492f-8875-cc8132a1b069>\",\"Content-Length\":\"138972\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5b8f5490-a156-4e04-808e-1aa6a2a06abe>\",\"WARC-Concurrent-To\":\"<urn:uuid:216f65b0-d443-4eca-ac52-ddb53f852130>\",\"WARC-IP-Address\":\"47.95.50.136\",\"WARC-Target-URI\":\"https://ask.csdn.net/questions/653241\",\"WARC-Payload-Digest\":\"sha1:FEPAQQQOBMRVG2NKIT5MCVSIJCVS6SL2\",\"WARC-Block-Digest\":\"sha1:QNN2JHP435AZJQZQGVL3FPWHSFWB7PP6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250616186.38_warc_CC-MAIN-20200124070934-20200124095934-00078.warc.gz\"}"}