(还有更简单的方法,待定——明天或者以后再说吧)
#include<iostream>
using namespace std;
void div(int a[],int n)
{
int* b1 = new int[n](), * b2 = new int[n]();
//int b1[100] = { 0 }, b2[100] = {0};
int i, j=0, k=0;
for (i = 0; i < n; i++)
{
if (a[i] < 0)
b1[j++] = a[i];
else
if (a[i] > 0)
b2[k++] = a[i];
else
;
}
int* d = new int[n]();
//int d[100] = {0};
i = 0; j = 0;
while (b1[j])
d[i++] = b1[j++];
j = 0;
while (b2[j])
d[i++] = b2[j++];
for (i = 0; d[i]; i++)
cout << d[i]<<" ";
}
// -1 -3 6 -2 7 -8 0 -4 9 10
int main()
{
cout << "请输入一个序列,以9999作为结束标志:";
int a[100], i = 0, n = 0;
while (1)
{
cin >> a[i];
if (a[i] == 9999)break;
else
{
i++; n++;
}
}
//cout << n<<endl;
div(a, n);
return 0;
}
#include<iostream>
#include<queue>
using namespace std;
const int Max = 100;
queue<int>q1;
queue<int>q2;
queue<int>q3;
void Print(queue<int>q)
{
for (int i = 0; i < q.size(); i++)
{
int t = q.front();
cout << t << " ";
q.pop();
q.push(t);
}
}
int main()
{
int n; cin >> n;
int* a = new int[Max];
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (a[i] > 0)q1.push(a[i]);
else
if (a[i] < 0)q2.push(a[i]);
else
q3.push(a[i]);
}
//cout << q1.size();
cout<< q3.size() << endl;
Print(q1);
Print(q3);
Print(q2);
return 0;
}