|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
void CN_Array<T>::edit_CN_Node(int row, int col, T val)
{
CN<T> *prev=&H[row-1], *curr=H[row-1].right;
bool bfind = false;
//查找行中位置
do
{
if(curr->j==col-1)//列值等于输入的列
{
bfind=true;
break;
}
else if(curr->j>col-1)
}
prev= prev->right;
curr=curr->right;
}
while(curr->right!=&H[row-1]);
if(bfind)//发现链表中存在插入元素的节点
{
if(val!=0)//修改
{
curr->v=val;
cout<<"修改("<<row<<","<<col<<")节点值为"<<val<<"。"<<end1;
}
else//执行删除操作
{
CN<T> * col_prev=&H[col-1],* col_curr=H[col-1].down;
while(col_curr!=curr)//查找列中位置
{
col_prev=col_prev->down;
col_curr=col_curr->down;
}
prev->right=curr->right;
col_prev->down=curr->down;
delete curr;
tt--;
count<<"删除("<<row<<","<<col<<")节点!"<<end1;
}
}
else
{
if(val!=0)//插入新的节点
{
CN<T> * col_prev=&H[col-1],* col_curr=H[col-1].down;
while((col_curr->i<row-1)&&(col_curr->i!=-1))//查找列位置
{
col_prev=prev->down;
col_curr=col_curr->down;
}
CN<T> * p=new CN<T>;
p->i=row-1;
p->j=col-1;
p->v=val;
p->down=col_curr;
prev->right=p;
col_prev->down=p;
tt++;
count<<"插入("<<row<<","<<col<<")节点,值为"<<val<<"。"<<end1;
}
} |
|