Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <ctime>
- using namespace std;
- struct stiva{
- int info,cul;
- stiva *urm;
- }*vf;
- struct tija{
- int info;
- tija *urm;
- }*t[101],*q;
- void push(stiva *&vf,int x,int y)
- {
- stiva *q;
- if(vf==0)
- {
- vf=new stiva;
- vf->info=x;
- vf->cul=y;
- vf->urm=0;
- }
- else
- {
- q=new stiva;
- q->info=x;
- q->cul=y;
- q->urm=vf;
- vf=q;
- }
- }
- void adaug(tija *&vf, int x)
- {
- tija *q;
- if(vf==0)
- {
- vf=new tija;
- vf->info=x;
- vf->urm=0;
- }
- else
- {
- q=new tija;
- q->info=x;
- q->urm=vf;
- vf=q;
- }
- }
- void sim(stiva *s)
- {
- stiva *q;
- for(q=s;q;q=q->urm)
- adaug(t[q->cul],q->info);
- }
- int main()
- {
- int ma,n,x,i;
- vf=0;ma=0;
- cin>>n;
- srand(time(NULL));
- for(int i=1;i<=n;++i)
- {
- x=rand()%5;
- if(x>ma)
- ma=x;
- cout<<x<<" ";
- push(vf,i,x);
- }
- cout<<'\n';
- sim(vf);
- for(i=1;i<=ma;++i)
- {
- for(q=t[i];q;q=q->urm)
- cout<<q->info<<' ';
- cout<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement