我是学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楼的朋友 谢谢!!