codecamp

链表

#include "stdio.h"
#include "stdlib.h"
struct Student
{int n;
 struct Student *next;
};

int main()
{struct Student *head;
 void create(struct Student**);
 struct Student* proceed(struct Student*);
 void print(struct Student*);
 void del(struct Student*);
 create(&head);
 print(head);
 head=proceed(head);
 print(head);
 del(head);
 return 0;
}

void create(struct Student **p) 
{struct Student *p1,*p2;
 int i,n;
 printf("Please input n:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {  p1=(struct Student*)malloc(sizeof(struct Student));
    p1->n=i;
if(i==1)
*p=p1;
else
p2->next=p1;
    p2=p1;
 }
 p1->next=NULL;
}

void print(struct Student *head)
{struct Student *p=head;
 while(p!=NULL)
 {printf("%d ",p->n);
  p=p->next;  
 }
 printf("/n");
}

struct Student* proceed(struct Student *head)
{struct Student *p1,*p2,*t;
 p1=p2=head;
 p1=p1->next;
 while(p1!=NULL)
 {  t=p1->next;
    p1->next=p2;
if(p2==head)
  p2->next=NULL;
    p2=p1;
p1=t;
 }
 head=p2;
 return head;
}

void del(struct Student*head)
{struct Student *p1,*p2;
 p1=head;
 while(p1!=NULL)
 {  p2=p1;
    p1=p1->next;
    free(p2);
 }   

解方程
贪吃蛇游戏
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }