// 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 delX(int x){
Node *p;
p = head;
for(int i=1;i<x-1;i++){
p=p->next;
}
p->next=p->next->next;
}
int main(void){
int i,n,x;
initL(n);
delX(x);
printL();
freeL();
return 0;
}
Ly8gc2VubmtlaSBsaXN0CiAKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlI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KIAppbnQgbWFpbih2b2lkKXsKICAgIGludCBpLG4seDsKICAgIHNjYW5mKCIlZCIsJm4pOwogICAgaW5pdEwobik7CiAgICBzY2FuZigiJWQiLCZ4KTsKICAgIGRlbFgoeCk7CiAgICBwcmludEwoKTsKICAgIGZyZWVMKCk7CiAgICByZXR1cm4gMDsKfQ==