// 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[]) {
//ここを書く
head=NULL;
for(int i=0; i<n; i++){
Node *q = createN(a[i]); // 新しいノード
if (head==NULL || head->val >= q->val) {
q->next=head;
head=q;
}
else{
Node *p=head;
while(p->next!=NULL && p->next->val < q->val) {
p=p->next;
}
q->next=p->next;
p->next=q;
}
}
}
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+bmV4dDsKICAgIH0KfQoKdm9pZCBmcmVlTCgpewogICAgTm9kZSAqcDsKICAgIHdoaWxlKGhlYWQhPU5VTEwpewogICAgICAgIHAgPSBoZWFkLT5uZXh0OwogICAgICAgIGZyZWUoaGVhZCk7CiAgICAgICAgaGVhZCA9IHA7CiAgICB9Cn0KCnZvaWQgcHJpbnROKE5vZGUgKmEpewogICAgaWYoYSA9PSBOVUxMKSBwcmludGYoIk5VTExcbiIpOwogICAgZWxzZSBwcmludGYoIiVkXG4iLGEtPnZhbCk7Cn0KCnZvaWQgcHJpbnRMKCl7CiAgICBOb2RlICpwID0gaGVhZDsKICAg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ZCBpbnNUYWlsKGludCB4KXsKICAgIE5vZGUgKnA7CiAgICBwID0gaGVhZDsgICAgICAgICAgICAgICAvL++8kQogICAgaWYocD09TlVMTCl7CiAgICAgICAgaGVhZCA9IGNyZWF0ZU4oeCk7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgd2hpbGUocC0+bmV4dCAhPSBOVUxMKXsgLy/vvJIKICAgICAgICBwID0gcC0+bmV4dDsgICAgICAgIC8v77ySCiAgICB9CiAgICBwLT5uZXh0ID0gY3JlYXRlTih4KTsgICAvL++8kwp9Cgp2b2lkIGRlbEhlYWQoKXsKICAgIE5vZGUgKnA7CiAgICBwID0gaGVhZDsgICAgICAgICAgIC8v77yRCiAgICBoZWFkID0gaGVhZC0+bmV4dDsgIC8v77ySCiAgICBmcmVlKHApOyAgICAgICAgICAgIC8v77yTCn0KCnZvaWQgZGVsTWlkZGxlKGludCBuKXsKICAgIGludCBpOwogICAgTm9kZSAqcCwqcTsKICAgIHAgPSBoZWFkOyAgICAgICAgICAgLy/vvJEKICAgIGZvcihpPTE7aTxuLTE7aSsrKXsgLy/vvJIKICAgICAgICBwID0gcC0+bmV4dDsgICAgLy/vvJIKICAgIH0KICAgIHEgPSBwLT5uZXh0OyAgICAgICAgLy/vvJMKICAgIHAtPm5leHQgPSBxLT5uZXh0OyAgLy/vvJQKICAgIGZyZWUocSk7ICAgICAgICAgICAgLy/vvJUKfQoKdm9pZCBkZWxUYWlsKCl7CiAgICBOb2RlICpwOwogICAgcCA9IGhlYWQ7ICAgICAgICAgICAgICAgICAgICAgICAvL++8kQogICAgd2hpbGUocC0+bmV4dC0+bmV4dCAhPSBOVUxMKXsgICAvL++8kgogICAgICAgIHAgPSBwLT5uZXh0OyAgICAgICAgICAgICAgICAvL++8kgogICAgfQogICAgZnJlZShwLT5uZXh0KTsgICAgICAgICAgICAgICAgICAvL++8kwogICAgcC0+bmV4dCA9IE5VTEw7ICAgICAgICAgICAgICAgICAvL++8lAp9Cgp2b2lkIG1ha2VMKGludCBuLCBpbnQgYVtdKSB7CiAgICAKICAgIC8v44GT44GT44KS5pu444GPCiAgICBoZWFkPU5VTEw7IAoKICAgIGZvcihpbnQgaT0wOyBpPG47IGkrKyl7CiAgICAgICAgTm9kZSAqcSA9IGNyZWF0ZU4oYVtpXSk7IC8vIOaWsOOBl+OBhOODjuODvOODiQogICAgICAgIGlmIChoZWFkPT1OVUxMIHx8IGhlYWQtPnZhbCA+PSBxLT52YWwpIHsKICAgICAgICAgICAgcS0+bmV4dD1oZWFkOwogICAgICAgICAgICBoZWFkPXE7CiAgICAgICAgfQogICAgICAgIGVsc2V7CiAgICAgICAgICAgIE5vZGUgKnA9aGVhZDsKICAgICAgICAgICAgd2hpbGUocC0+bmV4dCE9TlVMTCAmJiBwLT5uZXh0LT52YWwgPCBxLT52YWwpIHsKICAgICAgICAgICAgICAgIHA9cC0+bmV4dDsKICAgICAgICAgICAgfQogICAgICAgICAgICBxLT5uZXh0PXAtPm5leHQ7CiAgICAgICAgICAgIHAtPm5leHQ9cTsKICAgICAgICB9CiAgICB9Cn0KCmludCBtYWluKHZvaWQpewogICAgaW50IGksbjsKICAgIGludCAqYTsKICAgIHNjYW5mKCIlZCIsJm4pOwogICAgYSA9IChpbnQqKW1hbGxvYyhzaXplb2YoaW50KSpuKTsKICAgIGZvcihpPTA7aTxuO2krKyl7CiAgICAJc2NhbmYoIiVkIiwmYVtpXSk7CiAgICB9CiAgICBtYWtlTChuLGEpOwogICAgcHJpbnRMKCk7CiAgICBmcmVlTCgpOwogICAgcmV0dXJuIDA7Cn0K