头插法和尾插法

#define SUCCESS 10000
#define FAILURE 10001
#include 
#include 
#include 

typedef int ElemType;
struct node
{
    ElemType data;
    struct node *next;
};
typedef struct node Node;
int main(int argc, char **argv)
{
    int n[50];
    int i;
    //Node *l;
    Node *l=(Node *)malloc(sizeof(Node)*1);
    if(NULL==l)
    {
        return FAILURE;
    }
    l->next = NULL;
    l->data = 9;
    Node *p=l;
    for(i = 0;i<10;i++)
    {
        Node *q =(Node *)malloc(sizeof(Node));
       // printf("node = %d\n", sizeof(Node));
        printf("please input:\n");
        scanf("%d",&q->data);
        q->next = p->next;
        p->next = q;
        printf("data = %d\n", q->data);
    }
    Node *p1 = l->next;
    for(i= 0;i<10;i++)
    {
        printf("%d\n", p1->data);
        p1 = p1->next;
    }
    return 0;
}
#define SUCCESS 10000
#define FAILURE 10001
#include 
#include 
#include 
typedef int ElemType;
struct node
{
    ElemType data;
    struct node *next;
};
typedef struct node Node;

int main(int argc, char **argv)
{
    Node *l = NULL;
    int n = 0;
    int i;
    l = (Node *)malloc(sizeof(Node)*1);
    Node *p=l;
    l->next = NULL;
    printf("please input:\n");
    while(n!=10)
    {
        Node *q=(Node *)malloc(sizeof(Node)*1);
        scanf("%d",&q->data);
        q->next = p->next;
        p->next = q;
        p = q;
        n++;
        }
        Node *a = l->next;
    for(i = 0;idata);
        a=a->next;
    }

    return 0;
}

 

你可能感兴趣的:(头插法和尾插法)