#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node
{
int mode;
struct node* pnext;
};
int main()
{
int n,i;
struct node* head;
struct node* tail;
struct node* p;
scanf("%d",&n);
head=(struct node*)malloc(sizeof(struct node));
head->pnext=NULL;
tail=head;
for(i=1;i<=n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->mode);
p->pnext=NULL;
tail->pnext=p;
tail=p;
}
p=head->pnext;
while(p!=NULL)
{
printf("%d",p->mode);
if(p->pnext!=NULL)
{
printf(" ");
}
else
{
printf("\n");
}
p=p->pnext;
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct node
{
int mode;
struct node* pnext;
}*head,*p;
int main()
{
int n,i;
scanf("%d",&n);
p=(struct node*)malloc(sizeof(struct node));
p->pnext=NULL;
for(i=0;i<n;i++)
{
head=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->mode);
head->pnext=p;
p=head;
}
while(p->pnext!=NULL)
{
printf("%d",p->pnext->mode);
if(p->pnext->pnext!=NULL)
{
printf(" ");
}
else
{
printf("\n");
}
p=p->pnext;
}
return 0;
}
#include <iostream>
using namespace std;
struct node {
int data;
node *pnext;
};
void Insert(node* head, int m,int data1)
{
node *p=head;
while(m--&&p->pnext!=NULL)
{
p=p->pnext;
}
node *ptr=new node;
ptr->data=data1;
ptr->pnext=p->pnext;
p->pnext=ptr;
}
void show(node *head)
{
node *pe=head->pnext;
while(pe!=NULL)
{
printf("%d ",pe->data);
pe=pe->pnext;
}
}
int main()
{
int m,x;
int n;
while(cin>>n){
node *head=new node;
head->pnext=NULL;
for(int i=1;i<=n;i++){
scanf("%d%d",&m,&x);
Insert(head,m,x);
}show(head);
}
return 0;
}
#include <iostream>
using namespace std;
struct node{
int data;
node *next;
};
node *create(int n){
node *head=new node;
head->next=NULL;
node* tail;
tail=head;
for(int i=1;i<=n;i++){
node* p=new node;
scanf("%d",&p->data);
p->next=tail->next;
tail->next=p;
}
return head;
}
void show(node *head){
node *p;
p=head->next;
while(p!=NULL)
{
if(p->next==NULL)
{printf("%d\n",p->data);
p=p->next;
}
else{
printf("%d ",p->data);
p=p->next;
}
}
}
node * cut(node *head, int n){
node *front;
node *back;
node *preback;
front=head;
back=front->next;
preback=front;
int flag;
while(front->next!=NULL)
{
while(back!=NULL)
{flag=0;
if(back->data==front->data)
{
preback->next=back->next;
n--;
flag=1;
}
if(flag){
back=back->next;
}
else{
back=back->next;
preback=preback->next;
}
}
if(front->next==NULL) break;
else{
front=front->next;
back=front->next;
preback=front;
}
}
cout<<n<<endl;
return head;
}
int main()
{
int n;
cin>>n;
node* head = create(n);
printf("%d\n",n);
show(head);
node *head1=cut(head,n);
show(head1);
return 0;
}
#include <iostream>
using namespace std;
struct node{
int data;
node *next;
};
node * create()
{
int n;
node *head,*tail,*p;
head=new node;
head->next=NULL;
tail = head;
while(~scanf("%d",&n)){
if(n==-1) break;
p= new node;
p->data=n;
p->next=tail->next;
tail->next=p;
}
return head;
}
void show(node *head){
node *p;
p=head->next;
while(p!=NULL)
{
if(p->next==NULL)
{printf("%d\n",p->data);
p=p->next;
}
else{
printf("%d ",p->data);
p=p->next;
}
}
}
int main(){
node *head= new node;
head=create();
show(head);
return 0;
}
#include <iostream>
using namespace std;
struct node {
int data;
node *next;
};
node *create(int n)
{
int x;
node *head=new node;
node *tail;
head->next=NULL;
tail=head;
for(int i=0;i<n;i++){
cin>>x;
node *p=new node;
p->data=x;
p->next=tail->next;
tail->next=p;
tail=p;
}
return head;
}
node *together_sort(node* head_1,node* head_2)
{
node *tail;
node * p=head_1->next;
node * q=head_2->next;
tail=head_1;
while(p!=NULL&&q!=NULL)
{
if(p->data>=q->data)
{
tail->next=q;
tail=q;
q=q->next;
}
else if(p->data<q->data)
{
tail->next=p;
tail=p;
p=p->next;
}
if(q) tail->next=q;
else tail->next=p;
}
return head_1;
}
void show(node *head)
{
node *p=head->next;
while(p!=NULL)
{
if(p->next==NULL)
{
printf("%d\n",p->data);
p=p->next;
}
else{
printf("%d ",p->data);
p=p->next;
}
}
}
int main()
{
int n,m;
cin>>n>>m;
node *head_1=create(n);
node *head_2=create(m);
head_1=together_sort(head_1,head_2);
show(head_1);
return 0;
}
#include <iostream>
using namespace std;
struct node{
int data;
node * next;
};
node *create(int n){
node *head=new node;
node *tail;
head->next=NULL;
tail=head;
for(int i=0;i<n;i++)
{
node *p=new node;
scanf("%d",&p->data);
p->next=tail->next;
tail->next=p;
tail=p;
}
return head;
}
node * dou(node * head1)
{
int n=0;
node* head=new node;
node* tail;
head->next=NULL;
tail=head;
node* p=head1->next;
while(p!=NULL)
{
if(p->data%2==0)
{
node *q=new node;
q->data=p->data;
q->next=tail->next;
tail->next=q;
tail=q;
n++;
}
p=p->next;
}
cout<<n<<' ';
return head;
}
node * you(node * head1)
{
int n=0;
node* head=new node;
node* tail;
head->next=NULL;
tail=head;
node* p=head1->next;
while(p!=NULL)
{
if(p->data%2!=0)
{
node *q=new node;
q->data=p->data;
q->next=tail->next;
tail->next=q;
tail=q;
n++;
}
p=p->next;
}
cout<<n<<endl;
return head;
}
void show(node *head)
{
node *p=head->next;
while(p!=NULL)
{
if(p->next==NULL) printf("%d\n",p->data);
else printf("%d ",p->data);
p=p->next;
}
}
int main()
{
int n;
cin>>n;
node * head=create(n);
node * head1,*head2;
head1=dou(head);
head2=you(head);
show(head1);
show(head2);
return 0;
}
#include <iostream>
using namespace std;
struct node{
int data;
node* front,*back;
};
node *creat(int n)
{
node* head=new node;
node * tail;
head->front=NULL;
head->back=NULL;
tail=head;
for(int i=0;i<n;i++){
node * p=new node;
scanf("%d",&p->data);
p->back=NULL;
tail->back=p;
p->front=tail;
tail=p;
}
return head;
}
void search(int x,node *head){
node *p=head->back;
while(p->data!=x)
p=p->back;
if(p->front==head)
printf("%d\n",p->back->data);
else if(p->back==NULL)
printf("%d\n",p->front->data);
else
printf("%d %d\n",p->front->data,p->back->data);
}
int main(){
int n,m;
int x;
cin>>n>>m;
node* head=creat(n);
for(int i=0;i<m;i++)
{
cin>>x;
search(x,head);
}
return 0;
}
#include <iostream>
#include <malloc.h>
using namespace std;
struct node {
int data;
node *next;
};
node * create(int n)
{
node *head=new node ;
node *tail;
head->data=1;
head->next=NULL;
tail=head;
for(int i=2;i<=n;i++)
{
node *p=new node;
p->data=i;
p->next=NULL;
tail->next=p;
tail=p;
}
tail->next=head;
return head;
}
int main()
{
int n,m;
cin>>n>>m;
node *head=create(n);
node *q,*p;
q=head;
while(q->next!=head)
q=q->next;
int con=0;
while(q->next!=q)
{
p=q->next;
con++;
if(con==m)
{
q->next=p->next;
free(p);
con=0;
}
else q=p;
}
printf("%d",q->data);
return 0;
}
#include <iostream>
#include <malloc.h>
using namespace std;
struct node{
int data;
node *next;
};
node * create(int n)
{
node *head=new node;
node *tail;
head->next=NULL;
head->data=1;
tail=head;
for(int i=2;i<=n;i++)
{
node *p=new node;
p->data=i;
p->next=NULL;
tail->next=p;
tail=p;
}
tail->next=head;
return head;
}
int main()
{
int n;
while(~scanf("%d",&n)&&n){
node *head;
node *p,*q;
head=create(n);
q=head;
while(q->next!=head)
q=q->next;
int con=0,ans=0;
while(q->next!=q)
{
p=q->next;
con++;
if(con==5){
if(p->data==1)
break;
q->next=p->next;
free(p);
con=0;
ans++;
}
else q=p;
}
printf("%d\n",ans+1);
}
return 0;
}