C++数据结构代码注释!

我是学JAVA的
朋友需要帮忙 注释一段C++源码
能力有限
希望懂得C++和数据结构的朋友
帮忙注视下谢谢
******************************************************
#include <iostream.h>
#include<stdlib.h>
#define MAX 100
typedef int datatype;
typedef struct List
{
datatype elem[MAX];
int Last;
}*SeqList;
SeqList InitList()
{
SeqList L;
L=(SeqList)malloc(sizeof(List));
L->Last=-1;
return L;
}
void CreateList(SeqList L)
{
int n;
cout<<"请输入你要创建的顺序表元素个数n= ";
cin>>n;
cout<<"请输入你要创建的顺序表:";
for(int i=0;i<n;i++)
{
cin>>L->elem[i];
L->Last++;
}
}
int Location(SeqList L,datatype x)
{
int i=0;
while(L->elem[i]!=x&&i<=L->Last)
{
i++;
}
if(i>L->Last)
return -1;
else
return i;
}
void Insertelem(SeqList L,datatype m)
{
int n;
cout<<"请输入你要插入的位置n=";
cin>>n;
if((L->Last+1)>MAX)
cout<<"表以满,能插入"<<endl;
else
{
L->Last++;
for(int i=L->Last;i>=n-1;i--)
{
L->elem[i+1]=L->elem[i];
}
L->elem[n-1]=m;
}
}
void Deleteelem(SeqList L,datatype m)
{
int i;

i=Location(L,m);
while(i==-1)
{
datatype n;
cout<<"你所查找的元素不在表中,请重新输入你要删除的元素"<<endl;
cin>>n;
i=Location(L,n);
}
for(int j=i;j<=L->Last;j++)
{
L->elem[i]=L->elem[i+1];
}
L->Last--;
}
void ShowList(SeqList L)
{
cout<<"当前顺序表元素为:";
for(int i=0;i<=L->Last;i++)
{
cout<<L->elem[i]<<" ";
}
cout<<endl;
}
void main()
{
SeqList L;
L=InitList();
CreateList(L);
int Opration;
cout<<"输入操作(1)为删除某元素(2)为插入(3)为查找(4)为输出当前顺序表(5)为退出"<<endl;
while(Opration!=5)
{
cin>>Opration;
if(Opration==1)
{
int n;
cout<<"请输入你要删除的元素n=";
cin>>n;
Deleteelem(L,n);
}
if(Opration==2)
{
int n;
cout<<"请输入你要插入的元素n=";
cin>>n;
Insertelem(L,n);
}
if(Opration==3)
{
datatype x;
cout<<"请输入你要查找的元素x=";
cin>>x;
cout<<"此元素在顺序表中的位置为:"<<Location(L,x)+1<<endl;
}
if(Opration==4)
{
ShowList(L);
}
if(Opration==5)
{
break;
}
}
}
要求每行都有注释。
最好还能有个整体注释,说明函数的调用,以及数据结构原理。
一旦采纳,再追加20分!
能不能将函数间的调用和关系说一下 2楼的朋友 谢谢!!

#include <iostream.h>
#include<stdlib.h>
#define MAX 100
typedef int datatype; //定义datatype为int类型
typedef struct List //list结构存储一个elem数组,和一个last值
{
datatype elem[MAX]; //定义一个elems数组元素类型int
int Last;
}*SeqList; //定义指向list类型的指针类型
SeqList InitList()
{
SeqList L;//L为seqlist类型的指针
L=(SeqList)malloc(sizeof(List));//开辟空间,空间大小LIST类型大小 强制转换为SEQLIST类型的指针 L赋值为指向新空间的指针
L->Last=-1;//为空间list中last赋值为-1
return L;//返回空间指针
}
void CreateList(SeqList L)
{
int n;
cout<<"请输入你要创建的顺序表元素个数n= ";
cin>>n;
cout<<"请输入你要创建的顺序表:";
for(int i=0;i<n;i++)
{
cin>>L->elem[i];//为seqlist结构L中elem[i]成员赋值
L->Last++; //last成员值加1
}
}
int Location(SeqList L,datatype x)
{
int i=0;
while(L->elem[i]!=x&&i<=L->Last) //逻辑与两个都必须为真才能继续L中的elem成员不等于x值,i也就是0<=L中last的成员值elem的个数
{
i++;
}
if(i>L->Last)//如果i>last成员值也就是总个数 函数返回-1否则返回i的值也就是在elem数组中的位置
return -1;
else
return i;
}
void Insertelem(SeqList L,datatype m)
{
int n;
cout<<"请输入你要插入的位置n=";
cin>>n;//在第n位置
if((L->Last+1)>MAX)//L的成员Last+1>100也就是元素个数大于100
cout<<"表以满,能插入"<<endl;
else
{
L->Last++;//个数加1
for(int i=L->Last;i>=n-1;i--)
{
L->elem[i+1]=L->elem[i];//把n的位置的值向右移动
}
L->elem[n-1]=m;//n位置的值赋予新的值
}
}
void Deleteelem(SeqList L,datatype m)
{
int i;

i=Location(L,m);//m在L中elem的位置
while(i==-1)//i不为-1一直循环可以参考location,表示没找到
{
datatype n;
cout<<"你所查找的元素不在表中,请重新输入你要删除的元素"<<endl;
cin>>n;
i=Location(L,n);
}
for(int j=i;j<=L->Last;j++)
{
L->elem[i]=L->elem[i+1];//elem第i个的值赋值为i+1的值,也就是删掉i
}
L->Last--;//元素个数减1
}
void ShowList(SeqList L)
{
cout<<"当前顺序表元素为:";
for(int i=0;i<=L->Last;i++)
{
cout<<L->elem[i]<<" ";//现实每个元素的值
}
cout<<endl;
}
void main()
{
SeqList L;//指向list类型的指针
L=InitList();//初始化
CreateList(L);//进行赋值
int Opration;
cout<<"输入操作(1)为删除某元素(2)为插入(3)为查找(4)为输出当前顺序表(5)为退出"<<endl;
while(Opration!=5)
{
cin>>Opration;//输入的值不为5一直循环
if(Opration==1)
{
int n;
cout<<"请输入你要删除的元素n=";
cin>>n;
Deleteelem(L,n);
}
if(Opration==2)
{
int n;
cout<<"请输入你要插入的元素n=";
cin>>n;
Insertelem(L,n);//插入元素n值
}
if(Opration==3)
{
datatype x;
cout<<"请输入你要查找的元素x=";
cin>>x;
cout<<"此元素在顺序表中的位置为:"<<Location(L,x)+1<<endl;//返回的是elem中元素的位置,数组从0开始所以第几个要+1
}
if(Opration==4)
{
ShowList(L);// 显示elem中的值
}
if(Opration==5)
{
break;
}
}
} /*1、先 InitList()初始化 2、CreateList(L)创建,要求输入elem元素个数,在为每个elem元素赋值
3,输出 "输入操作(1)为删除某元素(2)为插入(3)为查找(4)为输出当前顺序表(5)为退出"让用户选择,
不为5一直循环
选(1)"请输入你要删除的元素n=",要求输入删除的值n, Deleteelem(L,n)调用void Deleteelem(SeqList L,datatype m) m=n
Deleteelem函数里先调用 Location函数 查询是否存在这个值如果存在返回他在elem中的位置
把elem当前位置的值向前进1位,last-1就是总个数减1
选(2)"请输入你要插入的元素n="要求输入一个要插入的值n Insertelem(L,n)调用void Insertelem(SeqList L,datatype m) m=n
然后要求输入插入位置 n如果插入后元素的个数小于100可以插入把插入的位置的值向右移动
选(3) "请输入你要查找的元素x="输入要查找的值,然后 Location(L,x)调用 int Location(SeqList L,datatype x)
计算值在elem中的索引,索引是从0开始的,所以第几个就要加1,因为没有第0个
选(4) ShowList(L)用循环显示elem中每个的值
选(5)break强制退出循环,结束程序
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-10
int n;
cout<<"请输入你要插入的元素n=";