The non-adjacent element of the input matrix establishes a cross linked list and prints the complete program of the cross linked list in row mode.

Source: Internet
Author: User

/* Create a cross-linked list for the non-collar elements of the input matrix and print the complete program of the Cross-linked list in row mode */
Struct matnode/* cross linked list node definition */
{
Int row, col;
Struct matnode * right, * down;
Union {
Int val;
Struct matnode * next;
} Tag;
};
Struct matnode * createmat ()
{
Int m, n, t, s, I, r, c, v;
Struct matnode * h [100], * p, * q;/* h [] is the array of header pointers for each row in the cross linked list */
Printf ("number of rows m, number of columns n, number of non-zero elements t :");
Scanf ("% d, % d, % d", & m, & n, & t );
P = (struct matnode *) malloc (sizeof (struct matnode ));
H [0] = p;
P-> row = m;
P-> col = n;
S = m> n? M: n;
For (I = 1; I <= s; I ++)
{
P = (struct matnode *) malloc (sizeof (struct matnode ));
H [I] = p;
H [I-1]-> tag. next = p;
P-> row = p-> col = 0;
P-> down = p-> right = p;
}
H [s]-> tag. next = h [0];
For (I = 1; I <= t; I ++)/* t indicates the number of non-zero elements */
{
Printf ("t % d element (row number m, column number n, value v):", I );
Scanf ("% d, % d, % d", & r, & c, & v );
P = (struct matnode *) malloc (sizeof (struct matnode ));
P-> row = r;
P-> col = c;
P-> tag. val = v;
Q = h [r];
While (q-> right! = H [r] & q-> right-> col <c)
Q = q-> right;
P-> right = q-> right;
Q-> right = p;
Q = h [c];
While (q-> down! = H [c] & q-> down-> row <r)
Q = q-> down;
P-> down = q-> down;
}
Return (h [0]);
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.