Да се напише програма, която позволява да се въведат N на брой числа и след това извежда първо само положителните, а после само отрицателните числа от въведените.
По желание: Да се реши задачата в случая на въвеждане на числа до въвеждане на 0.
Да се напише програма, която позволява да се въведат N на брой числа и след това извежда първо само положителните, а после само отрицателните числа от въведените.
По желание: Да се реши задачата в случая на въвеждане на числа до въвеждане на 0.
Трябва да влезете, за да публикувате коментар.
#include <iostream> #include <iomanip> #include <windows.h> using namespace std; // ?????????? ???? ???????? ? ???????? const int N=5; class Queue { private: // ???????? ??? ????? ?? ???????? int head; // ???????? ??? ???? ?? ???????? int tail; // ????? ?? ?????????? ?? ?????????? ?? ???????? int s[N]; // ?????????????? ?? ???????? void init(); public: Queue(); // ???????? ???? ???????? ? ?????? bool isEmpty(); // ???????? ???? ???????? ? ????? bool isFull(); // ????? ?? ???????? ? ???????? bool push(int X); // ????????? ?? ???????? ?? ???????? bool pop(int &X); // ????? ?? ???????? void print(); }; Queue::Queue() { init(); } // ?????????????? ?? ???????? void Queue::init() { head=0; tail=0; for(int i=0;i<=N;i++) s[i]=0; } // ???????? ???? ???????? ? ?????? bool Queue::isEmpty() { return head==tail; } // ???????? ???? ???????? ? ????? bool Queue ::isFull() { return ((tail+1)%N)==head; } // ????? ?? ???????? ? ???????? bool Queue::push(int X) { bool ok = !isFull(); if (ok){ s[tail] = X; tail++; tail%=N; } return ok; } // ????????? ?? ???????? ?? ???????? bool Queue::pop(int &X) { bool ok = !isEmpty(); if (ok) { X = s[head]; head++; head%=N; } return ok; } // ????? ?? ???????? void Queue::print() { cout<<endl<<"head : "<<head<<" tail: "<<tail<<"\nqueue: | "; if(!isEmpty()) if (head<=tail) for(int i=head;i<tail;i++) cout<<setw(3)<<s[i]<<" | "; else { for(int i=head;i<N;i++) cout<<setw(3)<<s[i]<<" | "; for(int i=0;i<tail;i++) cout<<setw(3)<<s[i]<<" | "; } cout<<endl<<"array: | "; for(int i=0;i<N;i++) cout<<setw(3)<<s[i]<<" | "; cout<<endl<<"index: | "; for(int i=0;i<N;i++) cout<<setw(3)<<i<<" | "; cout<<endl<<endl; } int main ( ) { Queue s1,s2; int n, chislo; cout<<"Vavedete broi chisla: "; cin>>n; for (int i=0; i<n; i++) { cin>>chislo; if (chislo>0) s1.push(chislo); else s2.push(chislo); } cout<<"Polojitelnite chisla sa: "<<endl; while (!s1.isEmpty()) { s1.pop(n); cout<<n<<endl; } cout<<"Otricatelnite chisla sa: "<<endl; while (!s2.isEmpty()) { s2.pop(n); cout<<n<<endl; } system("pause"); return 0; }Браво!