





C++ Program for Bubble sort. /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program for Bubble sort ***************************************************************/ #include<iostream.h> #include<conio.h> void main() { int array[100],n,i,j,temp; clrscr(); cout<<"How many numbers–> "; cin>>n; cout<<"Enter "<<n<<" numbers\n"; for(i=0;i<n;i++) cin>>array[i]; for(i=0;i<n;i++) { for(j=0;j<n-1;j++) if(array[j]>array[j+1]) { temp=array[j]; array[j]=array[j+1]; array[j+1]=temp; } } cout<<"\nArray is sorted in ascending order.\n"; for(i=0;i<n;i++) cout<<array[i]<<" "; getch(); }/************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program for Bubble sort ***************************************************************/ #include<iostream.h> #include<conio.h> […]
C++ Program Program for Binary Search. /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program Program for Binary Search. ***************************************************************/ #include<iostream.h> #include<conio.h> #include<process.h> void main() { int ar[100],beg,mid,end,i,n,search; clrscr(); cout<<"How many numbers in the array: "; cin>>n; cout<<"Enter "<<n<<" numbers in ascending order –> "; for(i=0;i<n;i++) cin>>ar[i]; beg=0; end=n-1; cout<<"Enter a number to search: "; cin>>search; while(beg<=end) { mid=(beg+end)/2; if(ar[mid]==search) { cout<<"\nItem found at position "<<(mid+1); getch(); exit(0); } if(search>ar[mid]) beg=mid+1; else end=mid-1; […]
C++ Program to implement a stack using linked list. /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program to implement a stack using linked list. ***************************************************************/ #include<conio.h> #include<iostream.h> #include<process.h> #include<malloc.h> // Creating a NODE Structure struct node { int data; struct node *next; }; // Creating a class STACK class stack { struct node *top; public: stack() // constructure { top=NULL; } void push(); // to insert an element void […]
C++ Program implement a stack using an array. /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program implement a stack using an array ***************************************************************/ #include<conio.h> #include<iostream.h> #include<process.h> void main() { int stack[150],top,n,i,max_stack,choice,element,n_pop; max_stack=150; coutn; cout
C++ Program to add and subtract 2 sparse matrices. /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program to add and subtract 2 sparse matrices ***************************************************************/ #include<conio.h> #include<iostream.h> #include<process.h> int main() { clrscr(); int sparse1[10][3],sparse2[10][3],sum[10][3],diff[10][3]; int m,n,p,q,t1,t2,s,d,element; int i,j; cout<<"Enter the number of rows and columns : "; cin>>m>>n; t1=t2=0; cout<<"\nEnter the first matrix("<<m<<"*"<<n<<"):\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { cin>>element; if(element!=0) { t1=t1+1; sparse1[t1][1]=i; sparse1[t1][2]=j; sparse1[t1][3]=element; } } } sparse1[0][1]=m; sparse1[0][2]=n; sparse1[0][3]=t1; […]
C++ Program to find the transpose of a Sparse matrix. /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program to find the transpose of a Sparse matrix ***************************************************************/ #include<conio.h? #include<iostream.h? #include<process.h? void main() { clrscr(); int sparse[10][10],transpose[10][10]; int m,n,p,q,t,col,element; int i,j; cout<<"Enter the number of rows and columns : "; cin>>m>>n; t=0; // assigning the value of matrix cout<<"\nEnter the matrix:\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { cin>>element; if(element!=0) { t=t+1; sparse[t][1]=i; sparse[t][2]=j; […]
C++ Program to implement a single linked list and Perform the following operations. /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program to implement a single linked list and Perform the following operations 1: Insertioin 2: Deletion 3: Display ***************************************************************/ #include<conio.h> #include<iostream.h> #include<process.h> // Creating a NODE Structure struct node { int data; // data struct node *next,*start; // link to next node and previous node }; // Creating a class […]
C++ Program for Selection sort . /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program for Selection sort . ***************************************************************/ #include<conio.h> #include<iostream.h> #include<process.h> void main() { int array[100],n,i,j,temp; clrscr(); cout<<"How many numbers–> "; cin>>n; cout<<"Enter "<<n<<" numbers\n"; for(i=0;i<n;i++) cin>>array[i]; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) if(array[i]>array[j]) { temp=array[i]; array[i]=array[j]; array[j]=temp; } } cout<<"\nArray is sorted in ascending order.\n"; for(i=0;i<n;i++) cout<<array[i]<<" "; getch(); } //———————- END——————–/************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program […]
C++ Program for QUICK SORT. /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program for QUICK SORT. ***************************************************************/ #include<conio.h> #include<iostream.h> #include<process.h> void quickSort(int numbers[], int array_size); void q_sort(int numbers[], int left, int right); int numbers[150]; int main() { clrscr(); int i,n; cout<<"How many numbers you want to sort: "; cin>>n; cout<<"Enter "<<n<<" numbers.\n"; for (i = 0; i<n; i++) cin>>numbers[i]; //perform quick sort on array q_sort(numbers,0,n-1); cout<<"Numbers are sorted\n"; […]
C++ Program to implement a QUEUE using linked list. /************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program to implement a QUEUE using linked list. ***************************************************************/ #include<conio.h> #include<iostream.h> #include<process.h> #include<malloc.h> // Creating a NODE Structure struct node { int data; struct node *next; }; // Creating a class QUEUE class queue { struct node *frnt,*rear; public: queue() // constructure { frnt=rear=NULL; } void insert(); // to insert an element void del(); […]