Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
第一次用链表,不知道哪里出错了,老运行出错,谁能帮我??#include<stdio.h> #include<stdlib.h> #define MAX 34000 typedef struct LNode { int data; struct LNode * next; }LNode, * LinkList; void InitLList(LinkList * l, LNode * p)//初始化一张空链表 { * l=(LNode *)malloc(sizeof(LNode)); (* l)->next=NULL; p=* l; } void InsertLNode(LinkList * l, LNode * p, int i)//在当前指针后插入新链结点 { p->next=(LNode *)malloc(sizeof(LNode)); p=p->next; p->data=i; p->next=NULL; } void DeleteLNode(LinkList * l, int num, LNode * p)//删除当前指针所指向的下一链结点 { LNode * q; if((p->next->data)%num==0) { if(p==(* l)) (* l)->next=(* l)->next->next; else { q=p->next; p->next=p->next->next; free(q); } } } int main() { int i, j, lucky[3005], n; LinkList * l; LNode * p; InitLList(l, p); for(i=2; i<=MAX; i++) InsertLNode(l, p, i); j=1; while(j<=3000) { lucky[j]=(* l)->next->data; p=(* l)->next; while(p!=NULL) { DeleteLNode(l, lucky[j], p); p=p->next; } j++; } while(scanf("%d", &n)==1 && n!=0) printf("%d\n", lucky[n]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator