// 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 makeL(int n, int a[]){
for(int i=0; i<n; i++){
Node *newNode=createN(a[i]);
if(head==NULL || head->val >=a[i]){
newNode->next=head;
head=newNode;
}else{
Node *p;
p=head;
while(p->next!=NULL && p->next->val<a[i]){
p=p->next;
}
newNode->next=p->next;
p->next=newNode;
}
}
}
int main(void){
int i,n;
int *a;
a
= (int*)malloc(sizeof(int)*n
); for(i=0;i<n;i++){
}
makeL(n,a);
printL();
freeL();
return 0;
}
Ly8gc2VubmtlaSBsaXN0CgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKdHlwZWRlZiBzdHJ1Y3Qgbm9kZSB7CiAgICBpbnQgdmFsOwogICAgc3RydWN0IG5vZGUgKm5leHQ7Cn1Ob2RlOwoKTm9kZSAqaGVhZCA9IE5VTEw7CgpOb2RlKiBjcmVhdGVOKGludCB4KXsKICAgIE5vZGUgKm5ld25vZGU7CiAgICBuZXdub2RlID0gKE5vZGUgKiltYWxsb2Moc2l6ZW9mKE5vZGUpKTsKICAgIG5ld25vZGUtPnZhbCA9IHg7CiAgICBuZXdub2RlLT5uZXh0ID0gTlVMTDsKICAgIHJldHVybiBuZXdub2RlOwp9Cgp2b2lkIGluaXRMKGludCBuKXsKICAgIGludCB4LGk7CiAgICBOb2RlICpwOwogICAgc2NhbmYoIiVkIiwmeCk7CiAgICBoZWFkID0gY3JlYXRlTih4KTsKICAgIHAgPSBoZWFkOwogICAgZm9yKGk9MTtpPG47aSsrKXsKICAgICAgICBzY2FuZigiJWQiLCZ4KTsKICAgICAgICBwLT5uZXh0ID0gY3JlYXRlTih4KTsKICAgICAgICBwID0gcC0+bmV4dDsKICAgIH0KfQoKdm9pZCBmcmVlTCgpewogICAgTm9kZSAqcDsKICAgIHdoaWxlKGhlYWQhPU5VTEwpewogICAgICAgIHAgPSBoZWFkLT5uZXh0OwogICAgICAgIGZyZWUoaGVhZCk7CiAgICAgICAgaGVhZCA9IHA7CiAgICB9Cn0KCnZvaWQgcHJpbnROKE5vZGUgKmEpewogICAgaWYoYSA9PSBOVUxMKSBwcmludGYoIk5VTExcbiIpOwogICAgZWxzZSBwcmludGYoIiVkXG4iLGEtPnZhbCk7Cn0KCnZvaWQgcHJpbnRMKCl7CiAgICBOb2RlICpwID0gaGVhZDsKICAgIHdoaWxlKH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lsKGludCB4KXsKICAgIE5vZGUgKnA7CiAgICBwID0gaGVhZDsgICAgICAgICAgICAgICAvL++8kQogICAgaWYocD09TlVMTCl7CiAgICAgICAgaGVhZCA9IGNyZWF0ZU4oeCk7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgd2hpbGUocC0+bmV4dCAhPSBOVUxMKXsgLy/vvJIKICAgICAgICBwID0gcC0+bmV4dDsgICAgICAgIC8v77ySCiAgICB9CiAgICBwLT5uZXh0ID0gY3JlYXRlTih4KTsgICAvL++8kwp9Cgp2b2lkIGRlbEhlYWQoKXsKICAgIE5vZGUgKnA7CiAgICBwID0gaGVhZDsgICAgICAgICAgIC8v77yRCiAgICBoZWFkID0gaGVhZC0+bmV4dDsgIC8v77ySCiAgICBmcmVlKHApOyAgICAgICAgICAgIC8v77yTCn0KCnZvaWQgZGVsTWlkZGxlKGludCBuKXsKICAgIGludCBpOwogICAgTm9kZSAqcCwqcTsKICAgIHAgPSBoZWFkOyAgICAgICAgICAgLy/vvJEKICAgIGZvcihpPTE7aTxuLTE7aSsrKXsgLy/vvJIKICAgICAgICBwID0gcC0+bmV4dDsgICAgLy/vvJIKICAgIH0KICAgIHEgPSBwLT5uZXh0OyAgICAgICAgLy/vvJMKICAgIHAtPm5leHQgPSBxLT5uZXh0OyAgLy/vvJQKICAgIGZyZWUocSk7ICAgICAgICAgICAgLy/vvJUKfQoKdm9pZCBkZWxUYWlsKCl7CiAgICBOb2RlICpwOwogICAgcCA9IGhlYWQ7ICAgICAgICAgICAgICAgICAgICAgICAvL++8kQogICAgd2hpbGUocC0+bmV4dC0+bmV4dCAhPSBOVUxMKXsgICAvL++8kgogICAgICAgIHAgPSBwLT5uZXh0OyAgICAgICAgICAgICAgICAvL++8kgogICAgfQogICAgZnJlZShwLT5uZXh0KTsgICAgICAgICAgICAgICAgICAvL++8kwogICAgcC0+bmV4dCA9IE5VTEw7ICAgICAgICAgICAgICAgICAvL++8lAp9Cgp2b2lkIG1ha2VMKGludCBuLCB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