This C program demonstrates how to represent a sparse matrix using linked lists. It defines a Node struct to hold the non-zero elements, row and column positions. A create_new_node function adds elements to the linked list. It prints the row positions, column positions and values by traversing the list. The main function initializes a 4x5 sparse matrix and adds non-zero elements to the linked list. It then prints the list, representing the sparse matrix using much less space than a regular matrix.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
90 views
C Program For Sparse Matrix Representation
This C program demonstrates how to represent a sparse matrix using linked lists. It defines a Node struct to hold the non-zero elements, row and column positions. A create_new_node function adds elements to the linked list. It prints the row positions, column positions and values by traversing the list. The main function initializes a 4x5 sparse matrix and adds non-zero elements to the linked list. It then prints the list, representing the sparse matrix using much less space than a regular matrix.
// This function prints contents of linked list // starting from start void PrintList(struct Node* start) { struct Node *temp, *r, *s; temp = r = s = start;