// sennkei list
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int val;
struct node *next;
}Node;
Node *head = NULL;
Node* createN(int x){
Node *newnode;
newnode
= (Node
*)malloc(sizeof(Node
)); newnode->val = x;
newnode->next = NULL;
return newnode;
}
void initL(int n){
int x,i;
Node *p;
head = createN(x);
p = head;
for(i=1;i<n;i++){
p->next = createN(x);
p = p->next;
}
}
void freeL(){
Node *p;
while(head!=NULL){
p = head->next;
head = p;
}
}
void printN(Node *a){
if(a
== NULL
) printf("NULL\n"); }
void printL(){
Node *p = head;
while(p != NULL){
p = p->next;
}
}
Node* getN(int n){
int i;
Node *p;
p = head;
for(i=1;i<n;i++) p = p->next;
return p;
}
int countL(){
int ret = 0;
Node *p = head;
while(p!=NULL){
p = p->next;
ret++;
}
return ret;
}
Node* searchX(int x){
Node *p;
for(p=head; p!=NULL; p=p->next){
if(p->val == x) break;
}
return p;
}
void insHead(int x){
Node *p; //1
p = createN(x); //1
p->next = head; //2
head = p; //3
}
void insMiddle(int n, int x){
int i;
Node *p,*q;
p = head; //1
for(i=1;i<n;i++){ //2
p = p->next; //2
}
q = createN(x); //3
q->next = p->next; //4
p->next = q; //5
}
void insTail(int x){
Node *p;
p = head; //1
if(p==NULL){
head = createN(x);
return;
}
while(p->next != NULL){ //2
p = p->next; //2
}
p->next = createN(x); //3
}
void delHead(){
Node *p;
p = head; //1
head = head->next; //2
}
void delMiddle(int n){
int i;
Node *p,*q;
p = head; //1
for(i=1;i<n-1;i++){ //2
p = p->next; //2
}
q = p->next; //3
p->next = q->next; //4
}
void delTail(){
Node *p;
p = head; //1
while(p->next->next != NULL){ //2
p = p->next; //2
}
p->next = NULL; //4
}
void push(int x){
insHead(x);
}
int pop(){
int val=head->val;
delHead();
return val;
}
void enqueue(int x){
insTail(x);
}
int dequeue(){
int val=head->val;
delHead();
return val;
}
int main(void){
int s1,s2,s3,q1,q2,q3;
push(1);
push(2);
push(3);
s1 = pop();
s2 = pop();
s3 = pop();
printf("%d %d %d\n",s1
,s2
,s3
);
//キュー
enqueue(1);
enqueue(2);
enqueue(3);
q1 = dequeue();
q2 = dequeue();
q3 = dequeue();
printf("%d %d %d\n",q1
,q2
,q3
);
freeL();
return 0;
}
Ly8gc2VubmtlaSBsaXN0CgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKdHlwZWRlZiBzdHJ1Y3Qgbm9kZSB7CiAgICBpbnQgdmFsOwogICAgc3RydWN0IG5vZGUgKm5leHQ7Cn1Ob2RlOwoKTm9kZSAqaGVhZCA9IE5VTEw7CgpOb2RlKiBjcmVhdGVOKGludCB4KXsKICAgIE5vZGUgKm5ld25vZGU7CiAgICBuZXdub2RlID0gKE5vZGUgKiltYWxsb2Moc2l6ZW9mKE5vZGUpKTsKICAgIG5ld25vZGUtPnZhbCA9IHg7CiAgICBuZXdub2RlLT5uZXh0ID0gTlVMTDsKICAgIHJldHVybiBuZXdub2RlOwp9Cgp2b2lkIGluaXRMKGludCBuKXsKICAgIGludCB4LGk7CiAgICBOb2RlICpwOwogICAgc2NhbmYoIiVkIiwmeCk7CiAgICBoZWFkID0gY3JlYXRlTih4KTsKICAgIHAgPSBoZWFkOwogICAgZm9yKGk9MTtpPG47aSsrKXsKICAgICAgICBzY2FuZigiJWQiLCZ4KTsKICAgICAgICBwLT5uZXh0ID0gY3JlYXRlTih4KTsKICAgICAgICBwID0gcC0+bmV4dDsKICAgIH0KfQoKdm9pZCBmcmVlTCgpewogICAgTm9kZSAqcDsKICAgIHdoaWxlKGhlYWQhPU5VTEwpewogICAgICAgIHAgPSBoZWFkLT5uZXh0OwogICAgICAgIGZyZWUoaGVhZCk7CiAgICAgICAgaGVhZCA9IHA7CiAgICB9Cn0KCnZvaWQgcHJpbnROKE5vZGUgKmEpewogICAgaWYoYSA9PSBOVUxMKSBwcmludGYoIk5VTExcbiIpOwogICAgZWxzZSBwcmludGYoIiVkXG4iLGEtPnZhbCk7Cn0KCnZvaWQgcHJpbnRMKC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PSBxOyAgICAgICAgLy/vvJUKfQoKdm9pZCBpbnNUYWlsKGludCB4KXsKICAgIE5vZGUgKnA7CiAgICBwID0gaGVhZDsgICAgICAgICAgICAgICAvL++8kQogICAgaWYocD09TlVMTCl7CiAgICAgICAgaGVhZCA9IGNyZWF0ZU4oeCk7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgd2hpbGUocC0+bmV4dCAhPSBOVUxMKXsgLy/vvJIKICAgICAgICBwID0gcC0+bmV4dDsgICAgICAgIC8v77ySCiAgICB9CiAgICBwLT5uZXh0ID0gY3JlYXRlTih4KTsgICAvL++8kwp9Cgp2b2lkIGRlbEhlYWQoKXsKICAgIE5vZGUgKnA7CiAgICBwID0gaGVhZDsgICAgICAgICAgIC8v77yRCiAgICBoZWFkID0gaGVhZC0+bmV4dDsgIC8v77ySCiAgICBmcmVlKHApOyAgICAgICAgICAgIC8v77yTCn0KCnZvaWQgZGVsTWlkZGxlKGludCBuKXsKICAgIGludCBpOwogICAgTm9kZSAqcCwqcTsKICAgIHAgPSBoZWFkOyAgICAgICAgICAgLy/vvJEKICAgIGZvcihpPTE7aTxuLTE7aSsrKXsgLy/vvJIKICAgICAgICBwID0gcC0+bmV4dDsgICAgLy/vvJIKICAgIH0KICAgIHEgPSBwLT5uZXh0OyAgICAgICAgLy/vvJMKICAgIHAtPm5leHQgPSBxLT5uZXh0OyAgLy/vvJQKICAgIGZyZWUocSk7ICAgICAgICAgICAgLy/vvJUKfQoKdm9pZCBkZWxUYWlsKCl7CiAgICBOb2RlICpwOwogICAgcCA9IGhlYWQ7ICAgICAgICAgICAgICAgICAgICAgICAvL++8kQogICAgd2hpbGUocC0+bmV4dC0+bmV4dCAhPSBOVUxMKXsgICAvL++8kgogICAgICAgIHAgPSBwLT5uZXh0OyAgICAgICAgICAgICAgICAvL++8kgogICAgfQogICAgZnJlZShwLT5uZXh0KTsgICAgICAgICAgICAgICAgICAvL++8kwogICAgcC0+bmV4dCA9IE5VTEw7ICAgICAgICAgICAgICAgICAvL++8lAp9Cgp2b2lkIHB1c2goaW50IHgpewoJaW5zSGVhZCh4KTsKfQoKaW50IHBvcCgpewoJaW50IHZhbD1oZWFkLT52YWw7CglkZWxIZWFkKCk7CglyZXR1cm4gdmFsOwp9Cgp2b2lkIGVucXVldWUoaW50IHgpewoJaW5zVGFpbCh4KTsKfQoKaW50IGRlcXVldWUoKXsKCWludCB2YWw9aGVhZC0+dmFsOwoJZGVsSGVhZCgpOwoJcmV0dXJuIHZhbDsKfQoKaW50IG1haW4odm9pZCl7CglpbnQgczEsczIsczMscTEscTIscTM7CgkKICAgIHB1c2goMSk7CiAgICBwdXNoKDIpOwogICAgcHVzaCgzKTsKICAgIHMxID0gcG9wKCk7CiAgICBzMiA9IHBvcCgpOwogICAgczMgPSBwb3AoKTsKICAgIHByaW50ZigiJWQgJWQgJWRcbiIsczEsczIsczMpOwoKICAgIC8v44Kt44Ol44O8CiAgICBlbnF1ZXVlKDEpOwogICAgZW5xdWV1ZSgyKTsKICAgIGVucXVldWUoMyk7CiAgICBxMSA9IGRlcXVldWUoKTsKICAgIHEyID0gZGVxdWV1ZSgpOwogICAgcTMgPSBkZXF1ZXVlKCk7CiAgICBwcmludGYoIiVkICVkICVkXG4iLHExLHEyLHEzKTsKCiAgICBmcmVlTCgpOwogICAgcmV0dXJuIDA7Cn0K