链表操作的测试

来源:互联网 发布:ubuntu 移除源 编辑:程序博客网 时间:2024/05/15 23:43
//1、不含头结点的链表实现


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


int main()
{
    struct node* head = NULL;
    int a,x,position;
    printf("1 for Insert,2 for delete:\n");
    while(scanf("%d",&a))
    {
        if(a==1)
        {
            printf("Input the position and element:\n");
            scanf("%d %d",&position,&x);
            head=Insert(head,position,x);
            Print(head);
        }
        else
        {
            printf("Input the element you want to delete:\n");
            scanf("%d",&x);
            head=DelNode(head,x);
            Print(head);


        }


        printf("1 for Insert,2 for delete:\n");
    }


    return 0;

}


//2、带有头结点的链表实现



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


int main()
{
    struct node* head = NULL;
    int a,x,position;
    head=InitialList(head);
    printf("1 for Insert,2 for delete:\n");
    while(scanf("%d",&a))
    {
        if(a==1)
        {
            printf("Input the position and element:\n");
            scanf("%d %d",&position,&x);
            head=Insert(head,position,x);
            Print(head);
        }
        else
        {
            printf("Input the element you want to delete:\n");
            scanf("%d",&x);
            head=DelNode(head,x);
            Print(head);


        }


        printf("1 for Insert,2 for delete:\n");
    }


    return 0;
}
原创粉丝点击