-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCTRICK.cpp
More file actions
61 lines (57 loc) · 727 Bytes
/
CTRICK.cpp
File metadata and controls
61 lines (57 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
using namespace std;
struct node
{
int info;
node *next;
};
void insert(node **list,node *temp)
{
if(*list==NULL)
{
temp->next=temp;
*list=temp;
}
else
{
node *x=(*list)->next;
temp->next=x;
(*list)->next=temp;
for(int i=0;i<=temp->info;i++)
(*list)=(*list)->next;
}
}
int main()
{
node *list=NULL;
int t,n,y,s[50000];
cin>>t;
while(t--)
{
list=NULL;
cin>>n;
y=n;
while(n!=0)
{
node *temp=new node;
temp->info=n;
temp->next=NULL;
insert(&list,temp);
n--;
}
for(int i=0;i<y;i++)
{
s[i]=list->info;
list=list->next;
}
int pos=0;
for(int i=0;i<y;i++)
{
cout<<s[pos]<<" ";
if(pos==0)
pos=y-1;
else
pos--;
}
}
}