Sparse Matrix representation in Data Structure

  Рет қаралды 16

Right Click - Programming Made Easy

Right Click - Programming Made Easy

Күн бұрын

Пікірлер: 2
@rightclick80
@rightclick80 7 күн бұрын
SM Array Implementation #include #define MAX 100 struct SMatrix{ int r; int c; int val; }; int i,j; int createSM(int mat[MAX][MAX], int r, int c, struct SMatrix sm[MAX]) { int k=0,smr=0; for (i = 0; i < r; i++) { for (j = 0; j < c; j++) { if (mat[i][j] != 0) { sm[k].r = i; sm[k].c = j; sm[k].val = mat[i][j]; k++; smr++; } } } return(smr); } /*void scanmat(int mat[][], int r,int c) { printf("Enter the elements of the matrix: "); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { scanf("%d", &mat[i][j]); } } }*/ void printSM(struct SMatrix sm[MAX], int r) { for ( i = 0; i < r; i++) { printf("%d\t%d\t%d ", sm[i].r,sm[i].c,sm[i].val); } } void printmat(int mat[MAX][MAX], int r, int c) { for ( i = 0; i < r; i++) { for ( j = 0; j < c; j++) { printf("%d\t", mat[i][j]); } printf(" "); } } int main() { int r=6, c=10,smr; struct SMatrix sm[MAX]; int mat[MAX][MAX]={{0,1,0,0,0,2,0,0,0,0},{0,1,0,3,0,2,0,8,0,0},{0,1,0,0,4,2,0,7,0,0}, {3,6,0,6,0,2,0,0,9,0},{4,0,3,0,2,0,7,0,1,0},{0,9,0,0,4,2,0,7,5,0}}; //scanmat(mat,r,c); printmat(mat,r,c); smr=createSM(mat, r, c, sm); printf(" Sparse Matrix Representation: "); printSM(sm,smr); return 0; }
@rightclick80
@rightclick80 7 күн бұрын
SM Linked List Implementation #include #define MAX 100 struct node { int c,v; struct node * link; }; struct node *X[MAX], *t, *p; int i,j,smr; void createSM(int mat[MAX][MAX], int r, int c) { for (i = 0; i < r; i++) { for (j = 0; j < c; j++) { if (mat[i][j]!= 0) { p= malloc(sizeof(struct node)); p->c = j; p->v = mat[i][j]; p-> link = NULL; if(X[i] == NULL) X[i] = p; else { t = X[i]; while(t->link!= NULL){ t=t->link; } t-> link =p; } } } } } /*void scanmat(int mat[][], int r,int c) { printf("Enter the elements of the matrix: "); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { scanf("%d", &mat[i][j]); } } } */ void printSM(int r) { for ( i = 0; i < r; i++) { t = X[i]; // printf("Row\tColumn\tValue"); while(t!= NULL){ printf("%d\t%d\t%d ----> ", i, t->c, t->v); t=t->link; }printf(" "); } } void printmat(int mat[MAX][MAX], int r, int c) { for ( i = 0; i < r; i++) { for ( j = 0; j < c; j++) { printf("%d ", mat[i][j]); } printf(" "); } } int main() { int r=6, c=10; //struct SMatrix sm[MAX]; int mat[MAX][MAX]={{0,1,0,0,0,2,0,0,0,0},{0,1,0,3,0,2,0,8,0,0},{0,1,0,0,4,2,0,7,0,0},{3,6,0,6,0,2,0,0,9,0},{4,0,3,0,2,0,7,0,1,0},{0,9,0,0,4,2,0,7,5,0}}; //scanmat(mat,r,c); printmat(mat,r,c); createSM(mat, r, c); printf(" Sparse Matrix LL Representation: "); printSM(r); return 0; }
Types of queues in data structure
24:07
Right Click - Programming Made Easy
Рет қаралды 44
Linked List Implementation of a QUEUE
40:20
Right Click - Programming Made Easy
Рет қаралды 30
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
linked list implementation of stack
41:32
Right Click - Programming Made Easy
Рет қаралды 18
Queue Data Structure
24:49
Right Click - Programming Made Easy
Рет қаралды 38
trianle patterns using JAVA part1
17:14
Friend
Рет қаралды 25
Postfix Expression Evaluation using Stack in C
24:03
Right Click - Programming Made Easy
Рет қаралды 70
Applications of Stack
29:10
Right Click - Programming Made Easy
Рет қаралды 75
Bubble sort
11:19
Suchi Singh
Рет қаралды 94
Lecture - C Programming || Sort an array using Bubble Sort
33:35
Learn Programming
Рет қаралды 23
9.2 Finding Maximum In Two Dimensional Array in C++
11:18
Coding Fundamentals
Рет қаралды 8