# Tag: Arrays

## Program for representing multiple stacks in one array

Multiple Stacks in an array Program for representing multiple stacks in one array /*Implementing multiple stacks in a single array*/ #include <stdio.h> #include <stdlib.h> #include <conio.h> #define MAX 10 void push(int,int[],int,int); int pop(int,int[],int); void display(int,int[],int); /*array to top index for each stack*/ int t[MAX]; int top[MAX]; void main() { int arr[MAX],n,totstk,index; int i,j,k=0,span,no,ch,num; /*Input total […]

## Conversion of a Linked List into Array

Conversion of a Linked List into Array The conversion process involves creation of a linked list.  Then the list is read from the first node till the last node such that each node value is stored in an array and the node is removed by freeing its memory.  The array is then displayed as an […]

## Sparse Matrix representation for polynomials

Sparse Matrix representation for polynomials Program to represent two polynomials using Sparse Matrix representation using arrays, compute sum of two polynomials and represent the result using sparse matrix: /* Sparse Matrix Representation for Polynomials */ #include <stdio.h> #include <stdlib.h> #define MAX 15 int main(){ int poly1[MAX][MAX]={0},poly2[MAX][MAX]={0},poly3[MAX][MAX]={0}; int i,j,k,m,n,nrows,nrows1,nrows2,nrows3,ncols,ct=0,ct1=0,ct2=0; int spmat1[MAX][MAX]={0},spmat2[MAX][MAX]={0},spmat3[MAX][MAX]={0}; int deg,deg1,deg2,deg3; printf(“nEnter degree of […]

## Program to represent two polynomials using arrays and compute their sum

Sparse Polynomial representation and addition Program to represent two polynomials using arrays and compute their sum /* Representation of Polynomials using arrays */ /* Addition of two Polynomials */ #include <stdio.h> #define MAX 10 int main(){ int poly1[MAX]={0},poly2[MAX]={0},poly3[MAX]={0}; int i,deg1,deg2,deg3; printf(“nEnter degree of first polynomial?”); scanf(“%d”,&deg1); printf(“nEnter degree of second polynomial?”); scanf(“%d”,&deg2); printf(“nFor first polynomial:”); […]

## Sparse Polynomial representation and addition

Sparse Polynomial representation and addition: Polynomial is an expression which is composed of terms, wherein terms are composed of coefficient and exponent.  An example of a polynomial is: 4×3+5×2+6x+9.  This polynomial is composed of four terms with the following sets of coefficient and exponent – {(4,3), (5,2), (6,1), (9,0)}.  Thus representation of a polynomial using […]

## Program to represent Sparse Matrix using singly linked list (One dimensional list)

Sparse Matrix representation using singly Linked List: /* Sparse Matrix representation using linked list */ #include <stdio.h> #include <stdlib.h> typedef struct list{ int rows, cols, value; struct list *next; }list; list *create(){ list *temp = (list *)malloc(sizeof(list)); if(temp==NULL){ printf(“nMemory Allocation Error !”); exit(1); } return temp; } list *makenode(int r, int c, int val){ list […]

## Program to represent Sparse Matrix using arrays

Program to represent Sparse Matrix using arrays: /* Sparse Matrix representation using arrays */ #include <stdio.h> #include <stdlib.h> #define MAX 15 int main(){ int arr,i,j,m,n,nrows,ncols,ct=0; int sparse_matrix[MAX][MAX]; for(i=0;i<3;i++){ printf(“nEnter values for row %d?”,i+1); for(j=0;j<4;j++){ scanf(“%d”,&arr[i][j]); if(arr[i][j] != 0) ct++; } } nrows = ct+1; ncols = 3; sparse_matrix = 3; sparse_matrix = 4; sparse_matrix = […]

## Sparse Matrix

Sparse Matrix: A matrix that has minimum number of non-zero elements is called a sparse matrix i.e. very few elements are sparsely distributed in the matrix. Example: An array of order 3 x 4 containing sparsely located non-zero elements. 0 1 2 3 0 0 25 0 7 1 0 0 2 8 2 0 0 […]

## Array Representation – Column-major & Row-major

Array Representation: Column-major Row-major Arrays may be represented in Row-major form or Column-major form.  In Row-major form, all the elements of the first row are printed, then the elements of the second row and so on upto the last row.  In Column-major form, all the elements of the first column are printed, then the elements […]

## Program to delete a value from a given array such that array remains sorted

Sorted Deletion in an Array: Deletion is same as in previous post with the only difference that if the given array is sorted, then the deletion automatically will result in a sorted array. /* Sorted Deletion */ #include <stdio.h> #define MAX 10 int main(){ int arr[MAX],n,i,num; printf(“nEnter total numbers?”); scanf(“%d”,&n); for(i=0;i<n;i++){ printf(“nEnter number?”); scanf(“%d”,&arr[i]); } […]