单向循环链表的创建

#include<stdio.h>
#include<stdlib.h>
#define null 0
typedef struct node
{
    int number;
    struct node *next;
}student;
main()
{
    student *head,*p,*temp;
    int i;
    //建立链表头
    //head=p=(student*)malloc(sizeof(student));//分配地址
    head->number=1;
    head->next=NULL;
    //
    for(i=2;i<16;i++)
    {
        temp=(student*)malloc(sizeof(student));
        temp->number=i;
        temp->next=temp;
        head->next=temp;
        head=temp;
        //head->next;
    }
    head->next=p;
    while(p!=p->next)
    {
        p->next->next=p->next->next->next;
        p=p->next->next;
    }
    printf("%d\n",p->number);
}

 

posted on 2013-04-23 21:52  绕指柔yy  阅读(738)  评论(0编辑  收藏  举报

导航