主题:新手写的简单的十字链表类定义(C++)望大虾指点
第一次自己写 输入行值必须倒着输(以后要改进) 肯定有很多不成熟的地方 或者有可笑的地方
帮忙看看~
#include <iostream.h>
#define ROWMAX 3 //行数
#define LANMAX 4 //列数
struct Node
{
int row;
int lan;
int value;
Node* rnext; //NEXT行
Node* lnext; //NEXT列
};
class SZstack
{
protected:Node *Row[ROWMAX],*Lan[LANMAX];//行头和列头
public:
SZstack();
~SZstack();
void Create();
};
SZstack::SZstack()//初始化 定义指针为空
{
for(int i=0;i<ROWMAX;i++)
{
Row[i]=NULL;
Row[i]->rnext=NULL;
Row[i]->lnext=NULL;
}
for(int j=0;j<LANMAX;j++)
{
Lan[j]=NULL;
Lan[j]->rnext=NULL;
Lan[j]->lnext=NULL;
}
}
void SZstack::Create()
{
int Temp[LANMAX];//行输入存储
Node *iNode; //节点
for(int j=0;j<ROWMAX;j++)//一次性创建整个表
for(int i=0;i<LANMAX;i++)
{
cin>>Temp[i];
if(Temp[i]!=0) //不为零时 建立节点 设置相映的行和列指针
{
iNode=new Node;
iNode->rnext=Row[j]->rnext;
Row[j]->rnext=iNode;
iNode->rnext=NULL;
iNode->lnext=Lan[i]->lnext;
Lan[i]->lnext=iNode;
iNode->lnext=NULL;
iNode->row=j;
iNode->lan=i;
iNode->value=Temp[i];
}
}
}
void Main()
{
SZstack aa;
aa.Create();
}
帮忙看看~
#include <iostream.h>
#define ROWMAX 3 //行数
#define LANMAX 4 //列数
struct Node
{
int row;
int lan;
int value;
Node* rnext; //NEXT行
Node* lnext; //NEXT列
};
class SZstack
{
protected:Node *Row[ROWMAX],*Lan[LANMAX];//行头和列头
public:
SZstack();
~SZstack();
void Create();
};
SZstack::SZstack()//初始化 定义指针为空
{
for(int i=0;i<ROWMAX;i++)
{
Row[i]=NULL;
Row[i]->rnext=NULL;
Row[i]->lnext=NULL;
}
for(int j=0;j<LANMAX;j++)
{
Lan[j]=NULL;
Lan[j]->rnext=NULL;
Lan[j]->lnext=NULL;
}
}
void SZstack::Create()
{
int Temp[LANMAX];//行输入存储
Node *iNode; //节点
for(int j=0;j<ROWMAX;j++)//一次性创建整个表
for(int i=0;i<LANMAX;i++)
{
cin>>Temp[i];
if(Temp[i]!=0) //不为零时 建立节点 设置相映的行和列指针
{
iNode=new Node;
iNode->rnext=Row[j]->rnext;
Row[j]->rnext=iNode;
iNode->rnext=NULL;
iNode->lnext=Lan[i]->lnext;
Lan[i]->lnext=iNode;
iNode->lnext=NULL;
iNode->row=j;
iNode->lan=i;
iNode->value=Temp[i];
}
}
}
void Main()
{
SZstack aa;
aa.Create();
}