帮下忙 线性链表里的小问题

[复制链接]
查看11 | 回复1 | 2010-5-20 09:52:35 | 显示全部楼层 |阅读模式
#include
typedef struct ListNode
{

int data;

struct ListNode *next;
}ListNode,*LinkList;
LinkList InsList()
{

LinkList L;

ListNode *s,*p;

int len=1;

char x;

L=(ListNode *)malloc(sizeof(ListNode));

L->next=NULL;

p=L;

while(len)

{

printf("输入x:");

scanf("%c",&x);

if(x!='q')

{

s=(ListNode*)malloc(sizeof(ListNode));

s->data=x;

p->next=s;

p=s;

}

else

{

len=0;

s->next=NULL;

return L;

}

}
}
void ShowList(LinkList L)
{

ListNode *p;

p=L->next;

while(p!=NULL)

{

printf("值为:%c",p->data);

p=p->next;

}

printf("结束");
}
int lenList(LinkList L)
{

ListNode *p;

int len=0;

p=L->next;

while(p!=NULL)

{

p=p->next;

len++;

}

return len;
}
void main()
{

LinkList L;

int len;

system("graftabl 936");

clrscr();

L=InsList();

ShowList(L);

len=lenList(L);

printf("长度为:%d",len);

getch();

exit();
}
输入7个值,怎么得出的长度为14, 感觉怎么是双循环了下。

回复

使用道具 举报

千问 | 2010-5-20 09:52:35 | 显示全部楼层
#include #include typedef struct ListNode{
int data;
struct ListNode *next;}ListNode,*LinkList;LinkList InsList(){
LinkList L;
ListNode *s,*p;
int len=1;
char x;
L=(ListNode *)malloc(sizeof(ListNode));
L->next=NULL;
p=L;
while(len)
{pri
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行