简单链表

写了一堆烂代码。

#include <stdio.h>
#include <stdlib.h>

typedef struct _node{
    int data;
    struct _node *next;
}Node;

Node *create();
void append(Node *Head, int data);
void insert(Node *Head, int data, int pos);
void delete(Node *Head, int pos);
int length(Node *Head);
int find(Node *Head, int pos);
void output(Node *Head);

int main(){
    
    Node *head = create();
    append(head, 123);
    append(head, 456);
    append(head, 1234567);
    
    output(head);
    
    insert(head, 666, 2);
    insert(head, 777, 2);
    
    output(head);
    
    delete(head, 2);
    output(head);
    
    return 0;
}

Node *create(){
    Node *p = (Node *)malloc(sizeof(Node));
    p->next = NULL;
    return p;
}

void append(Node *Head, int data){
    Node *p = Head, *temp;
    while(p->next){
        p = p->next;
    }
    temp = (Node *)malloc(sizeof(Node));
    temp->data = data;
    temp->next = NULL;
    p->next = temp;
}

void insert(Node *Head, int data, int pos){
    Node *p = Head, *temp;
    int i, len;
    len = length(Head);

    for(i = 0; i<pos-1; i++){
        p = p->next;
    }
    temp = (Node *)malloc(sizeof(Node));
    temp->data = data;
    temp->next = p->next;
    p->next = temp;
    
}

void delete(Node *Head, int pos){
    Node *p = Head;
    int i;
    Node *pre, *del;
    for(i = 0; p->next && i<pos-1; i++){
        p = p->next;
    }
    pre = p;
    del = pre->next;
    pre->next = del->next;
    free(del);
}

int length(Node *Head){
    int i;
    Node *p = Head;
    for(i = 0; p->next; i++){
        p = p->next;
    }
    return i;
}

int find(Node *Head, int pos){
    Node *p = Head;
    int i;
    for(i = 0; p->next && i<pos; i++){
        p = p->next;
    }
    return p->data;
}

void output(Node *Head){
    Node *p = Head;
    do{
        p = p->next;
        printf("%d ", p->data);
    }while(p->next);
    printf("\n");
}