链表222222222222222

#include 
#include 

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

int main()
{
    Node * Head;
    Node * q;
    Node * last;
    Node * delet;


    Head = (Node*)malloc(sizeof(Node));
    Head->next=NULL;
    int i,num;
    for(i=1;i<=10;++i)
    {
        Node * p;
        p=(Node*)malloc(sizeof(Node));
        printf("Please input %d data:",i);
        scanf("%d",&num);
        p->data=num;
        p->next = Head->next;
        Head->next = p;
    }
    q=Head->next;
    for(i=1;i<=10;++i)
    {

        if(i==5)
            printf("NO.5 is %d\n",q->data);
        if(i==7)
            printf("NO.7 is %d\n",q->data);
        if(i==3)
            printf("NO.3 is %d\n",q->data);
        if(i==6)
            printf("NO.6 is %d\n",q->data);

        if(i==1)
            last=q;
        q=q->next;

    }
    printf("********************************************************************\n");
    printf("before delete first one:\n");
    q=Head->next;
    for(i=1;i<=10;++i)
    {
        printf("  %d",q->data);
        q=q->next;
    }
    printf("\nfirst is %d\n",last->data);
    printf("********************************************************************\n");
    printf("after delete first one:\n");
    q=Head->next;
    for(i=1;i<=10;++i)
    {
        if(i==1){
            delet = q;
            Head->next=q->next;
        }

            q=q->next;


    }
    q=Head->next;
    for(i=1;i<=9;++i)
    {

        printf("  %d",q->data );
        if(i==1)
            last=q;
        q=q->next;

    }
    printf("\nfirst is %d\n",last->data);


    return 0;
}

你可能感兴趣的:(日常练习,C语言)