### Need Help With Odd & Even Integers STACK

I Would Like The Program To Generate 15 Random Integers Into Array a, Then Push Both Even and Odd Integers Into One TEMP Stack. The Program Will Separate All Integers Into Odd & Even By Pulling Them Out In Incremental Order From The TEMP Stack. I Tried With The Even Integers First But The Program Did Not Display.

Could Someone Help Me Out, Please?

Here's The Program:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899`` ``````#include #include #include using namespace std; template class STACK { private: T ele[n]; int counter; public: void ClearStack() { counter = 0; } bool EmptyStack() { if (counter == 0) return true; else return false; } bool FullStack() { if (counter == n) return true; else return false; } void StackPush (T x) { ele[counter] = x; counter++; } T StackPop() { counter--; return ele[counter]; } }; int main () { //Declare Variables STACK <50, int> Even, Odd, Temp; //Clear All Stacks Even.ClearStack(); Odd.ClearStack(); Temp.ClearStack(); { int a[15]; srand(time(0)); //Assign 15 random Integers from 10 ~ 30 cout<<"Random numbers generated are: "; for (int i = 0; i < 15; ++i) { i = rand()%11+20; Even.StackPush(a[i]); Odd.StackPush(a[i]); while (!Even.EmptyStack()) { a[i] = Even.StackPop(); Temp.StackPush(a[i]); } } cout<
Let's Begin With Getting The Integers Into The Array. So, Instead Of

 ``12`` `````` i = rand() % 11 + 20;``````

We Use

 ``12`` `````` a[i] = rand() % 11 + 20;``````

Last But Not Least, The Order Of Operations Matters.

 ``1234567`` `````` a[i] = Temp.StackPop(); if (a[i] % 2 == 0) { Even.StackPush(a[i]); cout<< a[i] << " "; }``````

I'm leaving the odd ones to you, sir. Share the fun.
Topic archived. No new replies allowed.