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 …

Program for representing multiple stacks in one array Read More »

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 …

Sparse Matrix representation for polynomials Read More »

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:”); …

Program to represent two polynomials using arrays and compute their sum Read More »

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 …

Sparse Polynomial representation and addition Read More »

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 singly linked list (One dimensional list) Read More »

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[3][4],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[0][0] = 3; sparse_matrix[0][1] = 4; sparse_matrix[0][2] = …

Program to represent Sparse Matrix using arrays Read More »

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 …

Array Representation – Column-major & Row-major Read More »

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]); } …

Program to delete a value from a given array such that array remains sorted Read More »

You cannot copy content of this page.