本文整理汇总了C++中ArrayQueue类的典型用法代码示例。如果您正苦于以下问题:C++ ArrayQueue类的具体用法?C++ ArrayQueue怎么用?C++ ArrayQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testCtor
//Check to make sure that numItems returns correct result on a fresh
// instance of the ArrayQueue class
void testCtor(ArrayQueue<int>& testQueue){
if(testQueue.getNumItems() == 0){
std::cout << "SUCCESS: Fresh queue has 0 items" << std::endl;
} else {
std::cout << "ERROR: Fresh queue should have 0 items, but has " << testQueue.getNumItems() << std::endl;
}
}
示例2: main
int main()
{
string test = "s12fr3";
ArrayQueue<string> aQueue;
cout<<"The number is: "<<aQueue.getInteger(test);
// string Array;
// ArrayQueue<string> aQueue;
// int print = stoi(Array.c_str());
//
// cout << "========================================" << endl;
// cout << " ENTER THE INTEGER IN THE QUEUE " << endl;
// cout << "========================================" << endl;
// cout << "\t\tENTER THE NUMBER: ";
// cin >> Array;
// cout << "========================================" << endl;
// cout << endl;
// print = aQueue.getInteger(Array.c_str());
// cout << "========================================" << endl;
// cout << " GETINTEGER() FUNCTION DISPLAY " << endl;
// cout << "========================================" << endl;
// cout << "\t\t\tINTEGER: " << print << endl;
// cout << "========================================" << endl;
//
//
system("pause");
return 0;
}
示例3: main
int main()
{
ArrayQueue b;
b.enq("hi");
ArrayQueue a(b);
string hold = a.front();
//cout << hold << endl;
a.deq();
return 0;
}
示例4: create_queue
ArrayQueue<T> create_queue(int n)
{
cout << "Creating rval queue ";
ArrayQueue<T> q;
for (int i = 0; i < n; ++i)
cout << q.put(T(i)) << " ";
cout << endl;
return q;
}
示例5: testAroundTheHorn
//Test to see if your queue still works if we do add, remove, add, remove
// many times
void testAroundTheHorn(ArrayQueue<int>& testQueue){
for(int i=0;i<1000;i++){
testQueue.add(i);
int t = testQueue.remove();
if(t != i){
std::cout << "ERROR: Added " << i << " but got back " << t << std::endl;
return;
}
}
std::cout << "SUCCESS: Added and removed 1000 items successfully" << std::endl;
}
示例6: main
int main()
{
ArrayQueue q;
try
{
if(q.isEmpty())
{
cout << "Queue is empty" << "\n";
}
//Enqueue Elements
q.Enqueue(100);
q.Enqueue(200);
q.Enqueue(300);
//Size of queue
cout << "size of queue" << q.Size()<<"\n";
//Front elements
cout << q.Front() << "\n";
//Dequeue elements
cout << q.Dequeue() << "\n";
cout << q.Dequeue() << "\n";
cout << q.Dequeue() << "\n";
}
catch(...)
{
cout << "some exception occured" << "\n";
}
}
示例7: testAroundTheHorn
//Test to see if your queue still works if we do add, remove, add, remove
// many times
void testAroundTheHorn(ArrayQueue<int>& testQueue){
//std::cout << "IM reall HERE" << std::endl;
for (int i = 0; i<1000; i++){
testQueue.add(i);
int t = testQueue.remove();
//std::cout << "IM HERE"<<t<<"!!" << std::endl;
//breaks when trying to access i or t
if (t != i){
std::cout << "ERROR: Added " << i << " but got back " << t << std::endl;
return;
}
}
std::cout << "SUCCESS: Added and removed 1000 items successfully" << std::endl;
}
示例8: testGrow
//Test to see if your queue can grow to handle lots of items
void testGrow(ArrayQueue<int>& testQueue){
for(int i=0;i<1000;i++){
testQueue.add(i);
}
if(testQueue.getNumItems() != 1000){
std::cout << "ERROR: Should have 1000 items in queue, but only found " << testQueue.getNumItems() << std::endl;
return;
}
for(int i=0;i<1000;i++){
int t = testQueue.remove();
if(t != i){
std::cout << "ERROR: Added " << i << " but got back " << t << std::endl;
return;
}
}
std::cout << "SUCCESS: Added 1000 items, then removed 1000" << std::endl;
}
示例9: testRemoveException
//Test to make sure you are throwing an exception if remove is
// called improperly
void testRemoveException(ArrayQueue<int>& testQueue){
try {
int t = testQueue.remove();
} catch (std::string s) {
std::cout << "SUCCESS: Caught exception: " << s << std::endl;
return;
} catch (...) {
std::cout << "ERROR: Caught an exception, but it wasn't a string type" << std::endl;
return;
}
std::cout << "ERROR: Tried to remove from an empty queue, but did not get an exception" << std::endl;
}
示例10: print
void print(const ArrayQueue<T> & q)
{
cout << "capacity = " << q.capacity() << endl
<< "size = " << q.size() << endl;
for (int i = 0; i < q.size(); ++i)
cout << (T) q.front(i) << " ";
cout << endl ;
for (int i = 0; i < q.size(); ++i)
cout << (T) q.rear(i) << " ";
cout << endl
<< endl;
}
示例11: testAddRemove
//Add and remove some items, making sure they come back in the
// correct order
void testAddRemove(ArrayQueue<int>& testQueue){
testQueue.add(5);
testQueue.add(10);
testQueue.add(4);
if(testQueue.getNumItems() == 3){
std::cout << "SUCCESS: 3 items added" << std::endl;
} else {
std::cout << "ERROR: Added 3 items, but getNumItems says " << testQueue.getNumItems() << std::endl;
return;
}
int x = testQueue.remove();
int y = testQueue.remove();
int z = testQueue.remove();
if(x != 5 || y != 10 || z != 4){
std::cout << "ERROR: Expected 5, 10, 4, but got " << x <<", " << y << ", " << "z" << std::endl;
} else {
std::cout << "SUCCESS: 3 added items came back out in the correct order" << std::endl;
}
}
示例12: main
int main(int argc, char** argv) {
ArrayQueue MevaCua;
cout<< "Mida actual de la cua: " << MevaCua.size() << endl;
cout<< "Encuem 3 elements a la cua... " << endl;
MevaCua.enqueue('1');
MevaCua.enqueue('2');
try{
MevaCua.enqueue('3');
}
catch(CuaPlena& e){
cout << e.what() << endl;
}
MevaCua.print();
cout << "Cua plena (0:no, 1:si): " << MevaCua.full()<<endl;
cout<< "Treiem 1er element de la cua: "<<endl;
try{
MevaCua.dequeue();
}
catch(CuaBuida& e){
cout << e.what() << endl;
}
MevaCua.print();
cout<< "Treiem 2on element de la cua: " <<endl;
MevaCua.dequeue();
cout<< "Encuem 2 elements a la cua... " << endl;
MevaCua.enqueue('4');
MevaCua.enqueue('5');
cout<< "Treiem 3er element de la cua: " <<endl;
MevaCua.dequeue();
MevaCua.print();
cout<<"Mida actual de la cua: " << MevaCua.size() << endl;
cout<<"Cua buida (0:no, 1:si): " << MevaCua.empty()<<endl;
}
示例13: moveInto
/**
* Move all items on this queue into the given queue while
* retaining item order. The items will be inserted at the back of
* the target queue.
*
* @param q the target queue
**/
void moveInto(ArrayQueue<T> &q) {
while (_used > 0) {
q.emplace(std::move(access(0)));
pop();
}
}
示例14: main
/*
* Sequence of instructions that the queue object can run.
*/
int main(int argc, char** argv) {
ArrayQueue mevaCua (MAX_QUEUE);
cout << "Mida actual de la cua: " << mevaCua.size() << endl;
cout << "Encuem 3 elements a la cua..." << endl;
mevaCua.enqueue(1); mevaCua.enqueue(2); mevaCua.enqueue(3);
mevaCua.print();
cout << "Cua plena (0: no, 1: si): " << mevaCua.full() << endl;
cout << "Traiem 1er element de la cua: " << mevaCua.dequeue() << endl;
mevaCua.print();
cout << "Traiem 2on element de la cua: " << mevaCua.dequeue() << endl;
cout << "Encuem 2 elements a la cua... " << endl;
mevaCua.enqueue(4); mevaCua.enqueue(5);
cout << "Traiem 3er element de la cua: " << mevaCua.dequeue() << endl;
cout << "Mida actual de la cua: " << mevaCua.size() << endl;
mevaCua.print();
cout << "Cua buida (0:no, 1:si): " << mevaCua.empty() << endl;
return 0;
}
示例15: Stack
void Display::ShowDataStructItems()
{
ArrayStack<int> dsArrayStack;
ListStack<int> lsListStack;
ArrayQueue<int> aqArrayQueue;
CycleDoublyLinkList<int> dcllCycleDoublyLinkList;
BinarySearchTree<int> bstBinarySearchTree;
RedBlackTree<int> rbtRedBlackTree;
MergeFindSet<int> mfsMergeFindSet;
HashTable<int> htHashTable;
cout<<WELCOME_STRING<<endl;
cout<<"This is the Implement of Data Structs"<<endl;
cout<<"Please Select the Item you are Interest in:"<<endl;
cout<<"1. Stack(Implement of Array);"<<endl;
cout<<"2. Stack(Implement of List);"<<endl;
cout<<"3. Queue(Implement of Array);"<<endl;
cout<<"4. Cycle Doubly Linked List"<<endl;
cout<<"5. Binary Search Tree"<<endl;
cout<<"6. Red Black Tree"<<endl;
cout<<"7. Merge Find Set"<<endl;
cout<<"8. Hash Table"<<endl;
cout<<"98. Up Layer;"<<endl;
cout<<"99. Quit."<<endl;
cout<<STAR_STRING<<endl;
cout<<endl;
int nSelect;
while(1)
{
cin>>nSelect;
if(cin.fail())
{
ClearScreen();
cout<<"Input Error! Please Select Again!"<<endl;
cin.clear();
cin.sync();
ShowDataStructItems();
}
ClearScreen();
switch(nSelect)
{
case 1:
cout<<dsArrayStack.GetTitle().c_str()<<endl;
dsArrayStack.Description();
dsArrayStack.Test();
ShowDataStructItems();
break;
case 2:
cout<<lsListStack.GetTitle().c_str()<<endl;
lsListStack.Description();
lsListStack.Test();
ShowDataStructItems();
break;
case 3:
cout<<aqArrayQueue.GetTitle().c_str()<<endl;
aqArrayQueue.Description();
aqArrayQueue.Test();
ShowDataStructItems();
break;
case 4:
cout<<dcllCycleDoublyLinkList.GetTitle().c_str()<<endl;
dcllCycleDoublyLinkList.Description();
dcllCycleDoublyLinkList.Test();
ShowDataStructItems();
break;
case 5:
cout<<bstBinarySearchTree.GetTitle().c_str()<<endl;
bstBinarySearchTree.Description();
bstBinarySearchTree.Test();
ShowDataStructItems();
break;
case 6:
cout<<rbtRedBlackTree.GetTitle().c_str()<<endl;
rbtRedBlackTree.Description();
rbtRedBlackTree.Test();
ShowDataStructItems();
break;
case 7:
cout<<mfsMergeFindSet.GetTitle().c_str()<<endl;
mfsMergeFindSet.Description();
mfsMergeFindSet.Test();
ShowDataStructItems();
break;
case 8:
cout<<htHashTable.GetTitle().c_str()<<endl;
htHashTable.Description();
htHashTable.Test();
ShowDataStructItems();
break;
case 98:
goto ShowWelcome;
break;
case 99:
exit(0);
break;
default:
ClearScreen();
cout<<"Select Error! Please Select Again!"<<endl;
cin.clear();
cin.sync();
ShowDataStructItems();
//.........这里部分代码省略.........