编辑代码

/*
*创建和打印双向链表
*
*/
#include <stdio.h>
#include <stdlib.h>

#define TYPE struct stu
#define LEN sizeof (struct stu)
struct stu{
    int num;
    int age;
    struct stu *prior,*next;
};

TYPE *creat_LinkList(int n){
    struct stu *head,*pf,*pb;
    int i;
    for(i=0;i<n;i++){  
        pb=(TYPE*) malloc(LEN);
        printf("input Number and  Age\n");
        scanf("%d%d",&pb->num,&pb->age);
        if(i==0) pf=head=pb;    //头节点
        else                    //中间节点
        {
            pb->prior=pf;
            pf->next=pb;
            if(i==n-1){         //尾节点
            pb->next=head;
            head->prior=pb;
            }
        }
        pf=pb;
    }
    return(head);
}

int main () {
     //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
    printf("Hello JSRUN!   \n\n         - from C .");
    struct stu *p ,*pnow;
    p = creat_LinkList(4);
    pnow = p;
    for(int i=0 ; i<4 ; i++)
    {
        printf("num: %d, age: %d, p: %p, p->next: %p, p->prior: %p\n",pnow->num, pnow->age,pnow,pnow->next,pnow->prior);
        pnow=pnow->next;
    } 
    return 0;
}