题目内容 (请给出正确答案)
[主观题]

在Queue类中,Enqueue方法的作用是()。

提问人:网友owl721 发布时间:2022-01-07
参考答案
查看官方参考答案
如搜索结果不匹配,请 联系老师 获取答案
更多“在Queue类中,Enqueue方法的作用是()。”相关的问题
第1题
在Queue类中,Enqueue方法的作用是()

点击查看答案
第2题
阅读以下技术说明和Java代码,将Java程序中(1)~(5)空缺处的语句填写完整。[说明] 类Queue表示队列,

阅读以下技术说明和Java代码,将Java程序中(1)~(5)空缺处的语句填写完整。

[说明]

类Queue表示队列,类中的方法如表4-12所示。

阅读以下技术说明和Java代码,将Java程序中(1)~(5)空缺处的语句填写完整。[说明] 类Qu

类Node表示队列中的元素;类EmptyQueueException给出了队列中的异常处理操作。

[Java代码]

public class testmain { //主类

public static viod main (string args[]) {

Queue q= new Queue;

q.enqueue("first!");

q.enqueue("second!");

q.enqueue("third!");

(1) {

while(true)

system.out.println(q.dequeue());

}

catch((2) ) { }

}

public class Queue { //队列

node m_firstnode;

public Queue(){m_firstnode=null;}

public boolean isempty() {

if (m_firstnode= =null)

return true;

else

return false;

}

public viod enqueue(object newnode) { //入队操作

node next = m_firstnode;

if (next = = null) m_firstnode=new node(newnode);

else {

while(next.getnext() !=null)

next=next.getnext();

next.setnext(new node(newnode));

}

}

public object dequeue() (3) { //出队操作

object node;

if (is empty())

(4)

else {

node =m_firstnode.getobject();

m_firstnode=m_firstnode.getnext();

return node;

}

}

}

public class node{ //队列中的元素

object m_data;

node m_next;

public node(object data) {m_data=data; m_next=null;}

public node(object data,node next) {m_data=data; m_next=next;}

public void setobject(object data) {m_data=data; }

public object getobject(object data) {return m_data; }

public void setnext(node next) {m_next=next; }

public node getnext() {return m_next; }

}

public class emptyqueueexception extends (5) { //异常处理类

public emptyqueueexception() {

system. out. println ("队列已空!" );

}

}

点击查看答案
第3题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。 [说明] 这是一个模拟渡口管理

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

[说明]

这是一个模拟渡口管理的算法。某汽车轮渡口,过江渡船每次能载10辆车过江。过江车辆分为客车类和火车类,上船有如下规定:同类车先到先上船,客车先于货车上渡船,且每上4辆客车,才允许上一辆货车;若等待客车不足4辆,则以货车代替,若无货车等待则允许客车都上船。

程序中用到的函数有enqueue(queue*sq,elemtype*x)在队列sq中入队一个元素x;outqueue(queue*sq,elemtype*x)在队列sq中出队一个元素,并将其值赋给x;empty(queue*sq)判断队列sq是否为空队,若为空,返回1;否则返回0。

[C程序]

include<stdio.h>

void pass(){

queue bus,truct; /*bus表示客车队列,truck表示货车队列*/

char ch;

int n,tag; /* ]n为车号,tag为标志,tag=0表示客车,tag=1表示货车*/

intcount=0,countbus=0,counttruck=0; /*分别表示上渡船汽车数、客车数、货车数*/

while(1){

printf("输入命令: \n");

Scanf("%c",&ch);

switch(ch){

case'e':

case'E': printf("车号: \n");

Scanf("%d",&n);

printf("客车\货车(0\1): \n");

scanf("%d",&tag);

if((1) )

enqueue(&bus,n);

else

enqueue(&truck,n);

break;

case'i':

case'I': while(count<10){

if((2) && empty(&bus)==0){ /*客车出队*/

outqueue(&bus,&n);

printf("上船的车号为: \n");

count++;

(3) ;

}

eise if((4) ){ /*货车出队*/

countbus=0;

outqueue(&truck,&n);

printf("上船的车号为: \n");

count++;

counttruck++;

}

else if(empty(&bus)==0){

(5);

outqueue(&truck,&n);

printf("没有10辆车排队轮渡\n");

count++;

countbus++;

}

else{

printf("没有10辆车排队轮渡\n");

retUrn;

}

break;

}

case'q':

case'Q':break;

}

if(ch=='q' || ch=='Q')

break;

}

}

点击查看答案
第4题
写出以下程序段的输出结果(队列中的元素类型QElemType为char)。 void main() { Queue Q; InitQueu

写出以下程序段的输出结果(队列中的元素类型QElemType为char)。 void main() { Queue Q; InitQueue(Q); char x= ‘e’, y= ‘c’; EnQueue(Q, ‘h’); EnQueue(Q, ‘r’); EnQueue(Q, y); DeQueue(Q, x); EnQueue(Q, x); DeQueue(Q, x); EnQueue(Q, ‘a’); While(!QueueEmpty(Q)) { DeQueue(Q,y); cout<<y; }>

点击查看答案
第5题
试为第4章的队列结构增加Queue::getMax()接口,在O(1)时间内定位并读取其中最大元素。要求Queue::dequeue()接口的时间复杂度依然保持为O(1),Queue::enqueue()接口的时间复杂度不超过分摊的O(1)。

点击查看答案
第6题
下面程序段的输出结果是() void main() { Queue Q; InitQueue(Q); char x=’e’,y=’c’; EnQueue(Q,’h’); EnQueue(Q,’r’); EnQueue(Q,y); DeQueue(Q,x); EnQueue(Q,x); DeQueue(Q,x); EnQueue(Q,’a‘); while(!QueueEmpty(Q)) { DeQueue(Q,y); printf(y); } printf(x);

A.hrcha

B.rchah

C.rcha

D.char

点击查看答案
第7题
在Queue类中,移除并返回队列前端对象的方法是()

A.Dequene

B. Enqueue

C. Peek

D. Pop

点击查看答案
第8题
阅读下列算法,并回答问题: (1)Q、Q1和Q2都是队列结构,设队列Q=(1,0,-5,2,-4,-6,9),其中1为队头元

阅读下列算法,并回答问题:

(1)Q、Q1和Q2都是队列结构,设队列Q=(1,0,-5,2,-4,-6,9),其中1为队头元素,写出执行f31(&Q,&Q1,&Q2)之后队列Q、Q1和Q2的状态;

(2)简述算法f31的功能。

(注:InitQueue、EnQueue、DeQueue和QueueEmpty分别是队列初始化、入队、出队和判队空的操作)

void f31(Queue*Q,Queue*Q1,Queue*Q2){

int e;

InitQueue(Q1);

InitQueue(Q2);

while(!QueueEmpty(Q)){

e=DeQueue(Q);

if(e>=0)EnQueue(Q1,e);

else EnQueue(Q2,e);

}

}

点击查看答案
第9题
阅读算法f2,并回答下列问题:(1)设队列Q=(1,3,5,2,4,6)。写出执行算法f2后的队列Q;(2)简述算法f2的功能。voidf2(Queue*Q){DataTypee;if(!QueueEmpty(Q)){e=DeQueue(Q);f2(Q);EnQueue(Q,e);}}
点击查看答案
第10题
请完成算法填空,实现带表头结点的单链表形式实现的队...

请完成算法填空,实现带表头结点的单链表形式实现的队列上的元素入队与出队操作,队列和元素结点结构体定义如下: typedef struct node { ElemType element; struct node* link; }Node; typedef struct queue { Node* front; //注意front指向表头结点,非头结点,请对视频中提供的代码进行修改 Node* rear; //指向尾结点 }Queue; void EnQueue(Queue *Q, ElemType x) { Node* p= (Node*)malloc(sizeof(Node)); ____________ = x; p->link = NULL; ____________=p; Q->rear=p; } void DeQueue(Queue *Q) { //若队列为空,直接返回 if(___________ ==NULL) return; Node *p=_____________; Q->front->link=___________; free(p); //若出队后,队列为空,则需重置rear if(______________==NULL) Q->rear=Q->front;//指向表头结点 }

点击查看答案
账号:
你好,尊敬的用户
复制账号
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
欢迎分享答案

为鼓励登录用户提交答案,简答题每个月将会抽取一批参与作答的用户给予奖励,具体奖励活动请关注官方微信公众号:简答题

简答题官方微信公众号

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
简答题
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反简答题购买须知被冻结。您可在“简答题”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
简答题
点击打开微信