问题 单项选择题

设栈s和队列q的初始状态为空,元素a、b、c、d、e依次进入栈s,当一个元素从栈中出来后立即进入队列q。若从队列的输出端依次得到元素c、d、b、a、e,则元素的出栈顺序是 (1) ,栈s的容量至少为 (2)

2()

A.2

B.3

C.4

D.5

答案

参考答案:B

解析:

(1)队列是一种特殊的线性表,它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作。进行插入操作的端称为队尾,进行删除操作的端称为队头。队列中没有元素时,称为空队列。

队列具有先进先出(FIFO)的特点。

队列空的条件:front=rear

队列满的条件:rear=MAXSIZE

队列可以用数组Q[1…m]来存储,数组的上界m即是队列所允许的最大容量。在队列的运算中需设两个指针:head,队头指针,指向实际队头元素的前一个位置;tall,队尾指针,指向实际队尾元素所在的位置。一般情况下,两个指针的初值设为0,这时队列为空,没有元素。

队列中拥有的元素个数为:L=tail-head。现在要让排头的元素出队,则需将头指针加 1。如果想让一个新元素入队,则需将尾指针向上移动一个位置。

(2)栈是一种只能在叫做栈的一段进行进栈或者出栈操作的线性数据结构。栈的主要特点是“后进先出”,即后进栈的元素先处理。通常栈用顺序表存储,分配一块连续的内存区域存放栈中的元素,并用一个变量指向当前的栈顶。

栈的基本操作:

·置空栈initStack(s):设置一个空栈s。

·进栈push(s,x):将元素x进到栈s中,栈指针递增。

·pop(s,x):将栈s的栈顶元素赋给x,栈指针递减。

·判断栈空stackempty(s):若栈为空,返回1,否则返回0。

根据队列的特点,从队列的输出端依次得到元素c、d、b、a、e,则在从队列的输入端应依次输入元素c、d、b、a、e,则元素的出栈顺序是c、d、b、a、e,由于C是第一个出栈,而C是第三个出栈,所以栈s的容量至少为3。

判断题
阅读理解

请阅读下列应用文及相关信息,并按照要求匹配信息。请在答题卡上将对应题号的相应选项字母涂黑。

A. Pasta House – new Italian restaurant located in the heart of the city. Simple but delicious inexpensive meals. Also has a good range of vegetable-only meals. It’s always crowded so be ready to order take-away or share a table. Open 11 a.m. to midnight.

B. A Taste of India – famous for its spicy curries and many southern Indian dishes using chilli. You will usually be able to find a table during the week but if you’re planning to go on the weekend make sure you book a table in advance. Open noon to midnight.

C. Paris Match – this is the finest French restaurant in the city. Wonderful food you can enjoy in luxurious surroundings. The perfect place to have a romantic meal or impress a business partner, but be prepared for a large bill. Open noon to 2 a.m. Booking essential.

D. Mountain Diner – not fancy but tasty. Excellent Asian and European dishes. Countryside location surrounded by forest. It’s at least an hour’s drive from the city so you might want to stay at the nearby Mountain Hotel overnight. Open 7 a.m. to 10 p.m.

E. Owl Café – open 24 hours a day the café has a large selection of set breakfast, lunch and dinner meals for you to choose from, or you can enjoy one of their many delicious snacks and desserts over a cup of freshly made coffee.

F. Greek Bistro – a lively restaurant that serves great-value Greek food and has live Greek music played by a local band. Customers are encouraged to take part in the entertainment so be ready for a night of loud fun and laughter. Open 6 p.m. to 2 a.m.

以下是五个人的选择要求,请匹配每个人拟选择的地方:

小题1:Bill – was late getting up today so hasn’t had time to make breakfast. He wants to pick up something to eat before he goes to work so he has enough energy to last through to lunch time.

小题2:Julie – works in the city and wants to get some lunch. She doesn’t want anything too special so long as it is tasty and not too expensive. Julie likes all kinds of food but because she is on a diet she wants to avoid anything containing meat.

小题3:Sally – has friends visiting her from out-of-town and wants to take them to dinner. She wants to take them somewhere they can enjoy the atmosphere and have fun. She is a university student so doesn’t have a lot of money and doesn’t like her food too hot.

小题4: Albert – is a businessman who will meet an important European client for a business dinner next week. Want to book a table at a quiet restaurant that will impress his guest with both its food and its surroundings. 

小题5:Robert – is meeting his friend Ben for lunch today (Tuesday) and wants to take him to a nice restaurant. Both Robert and Ben enjoy good quality spicy food. Robert doesn’t like arranging things in advance so he hasn’t booked a table.