Programming Tools

where students meet to knowledge


Data Structure

C Program Sort elements Using Insertion Sort Algorithm

#include<stdio.h> int main() { int data[100],n,temp,i,j; printf(“Enter number of terms”); scanf(“%d”,&n); printf(“Enter elements”); for(i=0;i<n;i++) { scanf(“%d”,&data[i]); } for(i=1;i<n;i++) { temp=data[i]; j=i-1; while(temp<data[j] && j>=0) /*To sort elements in descending order, change temp<data[j] to temp>data[j] in above line.*/ { data[j+1] =… Continue Reading →

C Program To Sort data in ascending order using bubble sort

#include <stdio.h> int main() { int data[100],i,n,step,temp; printf(“Enter the number of elements to be sorted : “); scanf(“%d”, &n); for(i=0;i<n;i++) { printf(“Enter element”,i+1); scanf(“%d”,&data[i]); } for(step=0;step<n-1;step++) for(i=0;i<n-step-1;i++) { if(data[i]>data[i+1]) /* To sort in descending order, change > to < in… Continue Reading →

Stack Using array and perform operation PUSH,POP & Display

#include<stdio.h> #include<stdlib.h> void display(int*,int); int push(int*,int,int); int pop(int*,int); void main() { static int Top=0; int x,element,Stack[10],n; printf(“Enter the choice”); do { printf(“1.To insert an element”); printf(“2. To delete a element\n”); printf(“3.To display\n”); printf(“Enter correct choice”); scanf(“%d”,&n); switch(x) { case 1:printf(“Enter… Continue Reading →

What is Sparse Matrix? “Sparse Matrix is a matrix which contains very few non-zero elements”. A matrix can be defined with a 2-dimensional array. Any array with ‘m’ columns and ‘n’ rows represents a m*n matrix. There may be a… Continue Reading →

Find an element from Array using Linear search

#include<stdio.h> void main() { int a[10],i,n,flag=0,k; printf(“Enter element of an array\n”); for(i=0;i<10;i++) { scanf(“%d”,&a[i]); } printf(“Enter the number which you want to search\n”); scanf(“%d”,&n); for(i=0;i<10;i++) { if(a[i]==n) { flag=1; k=i; break; } } if(flag==1) { printf(“Number is found at %d… Continue Reading →

Transpose of given Array

#include<stdio.h> void main() { int m,n,i,j,mat[10][10],transp[10][10]; printf(“Enter the number of rows and cols\n”); scanf(“%d”,&m,&n); printf(“Enter the element of matrix\n”); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf(“%d”,&mat[i][j]); } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { transp[j][i]=mat[i][j]; } } printf(“Transpose of entered matrix is\n”); for(i=0;i<m;i++) {… Continue Reading →

Difference between Second maximum and second minimum In Array

#include<stdio.h> void main() { int a[10],i,max1,max2,min1,min2,s,k,d; printf(“Enter element of array\n”); for(i=0;i<10;i++) { scanf(“%d”,&a[i]); } max1=min1=a[0]; for(i=0;i<10;i++) { if(a[i]>max1) { s=i; if(a[i]<min1) { k=i; } } d=a[s]; d[s]=a[9]; a[9]=d; d=a[k]; a[k]=a[8]; a[8]=d; max2=min2=a[0]; for(i=0;i<8;i++) { if(a[i]>max2) { max2=a[i]; } if(a[i]<min2) {… Continue Reading →

Average of First Five Maximum Numbers In Array

#include<stdio.h> int main() { int i,j,max,sum=0,temp,a[10]; float avg; printf(“Enter element of array\n”); for(i=0;i<10;i++) { scanf(“%d”,&a[i]); } for(i=0;i<5;i++)  { max=0; for(j=0;j<10;j++) { if(a[j]>max) { max=a[j]; temp=j; } } a[temp]=0; sum=sum+max; } avg=sum/5;s printf(“%f is average”,avg); return 0; }

Threaded Binary Tree

A Binary tree is Threaded by making all right child pointers that would normally be ‘\0’ point to the inorder successor of the node (if it exists), and all left child pointers that would normally be ‘\0’ point to the inorder… Continue Reading →

Explain the advantages of binary search over Linear/Sequential search

Sequential search Linear searching is a searching techniques to find an items from a list until the particular item not reached at the end. We start the searching from 0 index to n-1 index in a Linear/Sequential manner, if particular… Continue Reading →

Function to determine if a particular item exist in the list

#include<stdio.h> #include<malloc.h> typedef struct _Node {  int val; struct _Node *next; }Node; Node *makeNode( int ); void print( Node * ); Node *locate( Node * , int ); void main( ) { Node *start = ‘\0’ , *last =’\0′ ,*nd; int n; printf(“\n”); while(1) { printf(“Enter Item : “);… Continue Reading →

  Data structures is a collection of rules, methods and algorithms for implementing collection of data and manage it for performing operations such as- Insertion Deletion Traversal Searching Sorting counting Contiguous List In Contiguous list, the items of the collection… Continue Reading →

© 2017 Programming Tools —