Home > Back-end >  Who can look at a wrong place, run out
Who can look at a wrong place, run out

Time:09-22

#include
#include
#include
#include
Struct linknode
{
Int rows, cols.
Down linknode * and * right;
The union vnext
{
Int v.
Linknode * next;
} the node;
};
Linknode * CreateMatlind ();
Linknode * InputMatlind (linknode, int);
Void ShowMatlind (linknode);
Void SearchMatlind (linknode * hm, int s);
Linknode * CreateMatlind ()
{
Int I, j, maxlin;
Hm linknode * and * cp [100], * p;
Printf (" \ n \ t \ t enter sparse matrix rows, the number of columns (use commas) : ");
The scanf (" % d, % d ", & amp; I, & amp; J);
If (i> J)
Maxlin=I;
The else
Maxlin=j;
Hm=new linknode;
Cp [0]=hm;
For (int l=1; L<=maxlin; L++)
{
P=new linknode;
p-> Rows=0;
p-> Cols=0;
p-> The down=p;
p-> Right=p;
Cp [l]=p;
Cp/l - 1 - & gt; Node. Next=p;
}
Cp [maxlin] - & gt; Node. Next=hm;
Hm=new linknode;
Hm - & gt; Rows=I;
Hm - & gt; Cols=j;
Return hm.
}
Linknode * InputMatlind (linknode * hm, int s)
{
Linknode * cp [100], * p, * q;
Int m, n, t;
Int I, j, k, maxlin;
I=hm - & gt; Rows;
J=hm - & gt; Cols.
If (i> J)
Maxlin=I;
The else
Maxlin=j;
Cp [0]=hm;
For (int l=1; L<=maxlin; L++)
{
P=new linknode;
p-> Rows=0;
p-> Cols=0;
p-> The down=p;
p-> Right=p;
Cp [l]=p;
Cp/l - 1 - & gt; Node. Next=p;
}
Cp [maxlin] - & gt; Node. Next=hm;
For (int x=0; x{
Printf (" \ n \ t \ t please enter the number of rows in the non-zero elements, column number and values (use commas) : ");
The scanf (" % d, % d, % d ", & amp; M, & amp; N, & amp; T);
P=new linknode;
p-> Rows=m;
p-> Cols=n;
p-> Node. V=t;
k=1;
Q=cp [m];
While (k)
{
If ((q - & gt; Right==cp [m]) | | (q - & gt; Right - & gt; Cols> N))
{
p-> Right=q - & gt; Right;
Q - & gt; Right=p;
K=0;
}
Else if (q - & gt; Right - & gt; Cols==n)
{
p-> Right=q - & gt; Right - & gt; Right;
Q - & gt; Right=p;
K=0;
}
Else if (q - & gt; Right - & gt; Cols{
Q=q - & gt; Right;
k=1;
}
}
k=1;
Q=cp [n].
While (k)
{
If ((q - & gt; The down==cp [n]) | | (q - & gt; The down - & gt; Rows> M))
{
p-> The down=q - & gt; The down;
Q - & gt; The down=p;
K=0;
}
Else if (q - & gt; The down - & gt; Rows==m)
{
p-> The down=q - & gt; The down - & gt; The down;
Q - & gt; The down=p;
K=0;
}
Else if (q - & gt; The down - & gt; Rows{
Q=q - & gt; The down;
k=1;
}
}
}
Return hm.
}
Void ShowMatlind linknode * (hm)
{
int m,n;
Linknode * p * q;
M=hm - & gt; Rows;
N=hm - & gt; Cols.
Q=p=hm - & gt; Node. The next;
P=p - & gt; Right;
coutPrintf (" \ n \ \ t t ");
For (int I=1; i<=m; I++)
{
For (int j=1; j<=n; J++)
{
If ((p - & gt; Rows==I) & amp; & (p - & gt; Cols==j))
{
Printf (" % d ", p - & gt; Node. V);
}
The else
Printf (" % c ", '0');
If ((j==n) & amp; & (p - & gt; Right==q))
break;
Else if (p - & gt; Right!=q)
P=p - & gt; Right;
}
Printf (" \ n \ n \ t \ t ");
P=q;
Q=p=p - & gt; Node. The next;
P=p - & gt; Right;
}
}
Void SearchMatlind (linknode * hm, int s)
{
Int m, n, k;
Linknode * p * q;
M=hm - & gt; Rows; N=hm - & gt; Cols.
Q=p=hm - & gt; Node. The next;
P=p - & gt; Right;
k=1;
While (k)
{
If ((p - & gt; Node. V)==s)
{
Printf (" \ n \ t \ n \ t line column value ");
Printf (" \ n \ t \ t element position: the first line % 2 d % 2 d % 2 d \ n ", p - & gt; Rows, p - & gt; Cols, p - & gt; Node. V);
K=0;
}
Else if (p - & gt; Right!=q)
P=p - & gt; Right;
The else
{
P=q;
Q=p=p - & gt; Node. The next;
If (p==hm)
{
Printf (" \ n \ t \ t curb without this element in the table! \n");
K=0;
}
P=p - & gt; Right;
}
}
}
Void main ()
{
Int s, k, ch=1;
int choice;
Hm linknode *=NULL;
While (ch)
{
printf("\n");
Printf (" \ n \ t \ t curb table of sparse matrix storage system \ n ");
Printf (" \ n \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
Printf (" \ n \ \ t t * 1 -- -- -- -- -- new productive capacity table * ");
Printf (" \ n \ t \ t * 2 -- -- -- -- -- display curb table * ");
Printf (" \ n \ t \ t * 3 -- -- -- -- -- looking for element * ");
Printf (" \ n \ t \ t * 0 - back out * ");
Printf (" \ n \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
Printf (" \ n \ n \ t \ t number: please enter the menu ");
The scanf (" % d ", & amp; Choice);
The switch (choice)
{
Case 1:
Hm=CreateMatlind ();
Do
{
Printf (" \ n \ t \ t please enter the number of nonzero elements sparse matrix: ");
The scanf (" % d ", & amp; S);
If (s> ((hm - & gt; Rows) * (hm - & gt; Cols)))
{
Printf (" \ n \ t \ t element number error! Should be less than or equal to % d \ n ", hm - & gt; Rows * hm - & gt; Cols);
k=1;
}
The else
K=0;
} while (k);
Hm=InputMatlind (hm, s);
break;
Case 2:
If (hm==NULL)
{
Printf (" \ n \ t \ t list is empty! \n");
break;
}
The else
{
ShowMatlind (hm);
break;
}
Case 3:
If (hm==NULL)
{
Printf (" \ n \ t \ t list is empty! \n");
break;
}
The else
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related