int main()
{int i,m,x,e,f;
linkquene<int> a,b;
cout<<"请输入要产生随机数的个数";
cin>>x;
srand(time(NULL));
cout<<"产生的随机数为:";
for(i=0;i<x;i++)
{m=rand()%100;
cout<<m<<" ";
if(m%2==0)a.pushtail(m);
else b.pushtail(m);}
cout<<endl;
cout<<"成对的奇数和偶数分别为"<<endl;
while(a.popfront(e)&&b.popfront(f))
{cout<<f<<" "<<e<<" "<<endl;}
return 0;
}
3题:
#include<iostream.h>
#include<assert.h>
template<class t1>
struct stacknode{
t1 data;
stacknode *next;};
template<class t1>
class linkstack{
stacknode<t1> *top;
unsigned height;
public:
linkstack();
~linkstack()
{clear();}
void clear();
void push(t1 &x);
bool pop(t1 &x);
bool isempty()
{return(height==0)?true:false;}
};
template<class t1>
linkstack<t1>::linkstack()
{height=0;
top=NULL;}