📄 pex12_7.cpp
字号:
#include <iostream.h>
#pragma hdrstop
#include "wex12_16.h"
void main(void)
{
// declare one queue for positive integers and one
// for negative integers
Queue<int> queuePos, queueNeg;
int n;
cout << "Input positive or negative integers. Enter "
<< " 0 to terminate input." << endl;
// read integers until a 0 is encountered. insert each
// positive integer into queuePos and each negative
// integer into queueNeg
cin >> n;
while(n)
{
if (n > 0)
queuePos.QInsert(n);
else
queueNeg.QInsert(n);
cin >> n;
}
// declare an iterator for queuePos
QueueIterator<int> qiter(queuePos);
// use the iterator to traverse and print queuePos
cout << "The postive integers are: " << endl;
for(qiter.Reset();!qiter.EndOfList();qiter.Next())
cout << qiter.Data() << " ";
cout << endl;
// set the iterator to traverse queueNeg
qiter.SetList(queueNeg);
cout << "The negative integers are: " << endl;
for(qiter.Reset();!qiter.EndOfList();qiter.Next())
cout << qiter.Data() << " ";
cout << endl;
}
/*
<Run>
Input positive or negative integers. Enter 0 to terminate input.
1 3 -9 7 -17 -67 21 15 55 -18 -99 5 0
The postive integers are:
1 3 7 21 15 55 5
The negative integers are:
-9 -17 -67 -18 -99
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -