Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

第一次用链表,不知道哪里出错了,老运行出错,谁能帮我??

Posted by VitaminC at 2005-12-03 20:24:57 on Problem 2552
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator