Q3.7 Create a data structures to hold dogs and cats.(待续)
2015-01-19 23:31
399 查看
Q: An animal shelter holds only dogs and cats, and operates on a strictly "first in, first out" basis. People must adopt either the "oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat
(and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat. You may use the
built-in L inkedL ist data structure.
A: 因为要保存cat和dog,以及其共同体,所以利用虚函数效果更好一些。
首先定义一个新的基本数据结构用来保存动物的名字和入住的顺序。并且用两个链表,分别用来继续dog和cat的数据。
enqueue:设定其order, 再将其加入相应的链表当中
dequeueAny:根据dog和cat第一个数据的顺序,判断返回哪一个数据
(and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat. You may use the
built-in L inkedL ist data structure.
A: 因为要保存cat和dog,以及其共同体,所以利用虚函数效果更好一些。
首先定义一个新的基本数据结构用来保存动物的名字和入住的顺序。并且用两个链表,分别用来继续dog和cat的数据。
enqueue:设定其order, 再将其加入相应的链表当中
dequeueAny:根据dog和cat第一个数据的顺序,判断返回哪一个数据
相关文章推荐
- Data Structures and algorithm analysis—1.3. A Brief Introduction to Recursion(数据结构—1.3 递归的简介)(之一)
- Introduction to graphs and their data structures Section III[翻译]
- An Introduction to Clustered and Non-Clustered Index Data Structures
- 171.View the Exhibit and examine the command used to create the ZONEDATA table.
- How to Create, Use and Maintain DataStage 8 Parameter Sets
- [问题解决] initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock
- Data Structures and algorithm analysis—1.3. A Brief Introduction to Recursion(数据结构—1.3 递归的简介)(之二)
- Introduction to graphs and their data structures Section II[翻译]
- Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.
- Peoplecode to Create BI publisher XML and XSD Data source file.
- How to create iOS 8 Today extension and share data with containing app – tutorial
- Introduction to graphs and their data structures Section I[翻译]
- using JS to control two select(html),the data can be loaded from database and XML,and show in the select
- Effective STL:Item 16: Know how to pass vector and string data to
- A Data Access Layer to persist business objects using attributes and reflection - Part II [无常译]
- A Data Access Layer to persist business objects using attributes and reflection - Part III [无常译]
- A Data Access Layer to persist business objects using attributes and reflection - Part I [无常译]
- How To Display Hierarchical Data by Using Nested Repeater Controls and Visual
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- Data Types and Data Structures (数据类型和数据结构)