首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

急求高手,解决数据结构的作业!先谢过了解决方法

2012-03-01 
急求高手,解决数据结构的作业!!先谢过了程序比较短,就没写注释了,学过的应该都能看得懂吧第一个函数是初始

急求高手,解决数据结构的作业!!先谢过了
程序比较短,就没写注释了,学过的应该都能看得懂吧     第一个函数是初始化     第二个函数是用单链表存放一个句子中每个字符出现的次数和位置       第三个是输出

#include <iostream>
using   namespace   std;
#define   MAXSIZE   32767
struct   InfoList
{char   data;
int   weight;
int   location[80];
struct   InfoList   *next;
}IL;
char   sen[MAXSIZE];

void   InitInfoList(InfoList   *&IL)
{
IL=(InfoList   *)malloc(sizeof(InfoList));
IL-> next=NULL;
}

void   CreateInfoList(char   sen[],InfoList   *&IL)
{int   i,j;
InfoList   *p=IL-> next,*s;
i=0;
while(sen[i]!= '\n ')
{

if(sen[i]==p-> data)
{
j++;
p-> weight++;
p-> location[j]=i;
}
else   if(p==NULL)
{
j=0;
s=(InfoList*)malloc(sizeof(InfoList));
s-> data=sen[i];
s-> weight=1;
s-> location[j]=i;
p-> next=s;
}
else   p=p-> next;
i++;
}

void   DispList(InfoList   *IL)
{
InfoList   *p=IL-> next;
while(p!=NULL)
{cout < <p-> data < < "   " < <p-> weight < < "   " < <p-> location[] < <endl;
p=p-> next;
}
cout < <endl;
}

int   main()
{
InitInfoList(IL);
CreateInfoList(sen[],IL);
DispList(IL);
return   0;
}

运行结果是--------------------Configuration:   info   -   Win32   Debug--------------------
Compiling...
info.cpp
E:\sourcefile\sourcefile\info.cpp(47)   :   error   C2601:   'DispList '   :   local   function   definitions   are   illegal
E:\sourcefile\sourcefile\info.cpp(57)   :   error   C2601:   'main '   :   local   function   definitions   are   illegal
E:\sourcefile\sourcefile\info.cpp(63)   :   fatal   error   C1004:   unexpected   end   of   file   found
Error   executing   cl.exe.

info.obj   -   3   error(s),   0   warning(s)


[解决办法]
链表指针头没有定义

void CreateInfoList(char sen[],InfoList *&IL)少了一个}

cout < <p-> data < < " " < <p-> weight < < " " < <p-> location[] < <endl;
p-> location[]
没有看懂这个是要干什么,有这么写的吗?
[解决办法]
好似c++和c语言都用到了。既然c++是面向对象的,那为什么还要用结构体呢?

热点排行