pex5_5.cpp

来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 39 行

CPP
39
字号
#include <iostream.h>
#pragma hdrstop

typedef int DataType;

#include "pex5_5.h"	// include definition of DualStack

void main (void)
{
	DualStack S;
	int i;
	int A[20] = {1,2,3,4,5,6,7,-8,-9,10,-11,12,-13,-14,15,16,17,18,0,-20}; 
	
	// cycle through a. push the even integers on stack 1
	// and the odd integers on stack 2
	for (i = 0; i < 20; i++)
	{
		if (A[i] % 2 == 0)
			S.Push(A[i], 1);
		else
			S.Push(A[i],2);
	}

	// print the two stacks
	while (!S.StackEmpty(1))
		cout << S.Pop(1) << "  ";
	cout << endl;
	while (!S.StackEmpty(2))
		cout << S.Pop(2) << "  ";
	cout << endl;
}

/*
<Run>

-20  0  18  16  -14  12  10  -8  6  4  2
17  15  -13  -11  -9  7  5  3  1
*/	 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?