-// Recursive C++ program to sort an array // using selection sort #include <iostream> using namespace std; // Return minimum index int minIndex(int a[], int i, int j) { if (i == j) return i; // Find minimum of remaining elements int k = minIndex(a, i + 1, j); // Return minimum […]
/C++ program for recursive implementation // of Bubble sort #include <bits/stdc++.h> using namespace std; // A function to implement bubble sort void bubbleSort(int arr[], int n) { // Base case if (n == 1) return; // One pass of bubble sort. After // this pass, the largest element // is moved (or bubbled) […]
#include <iostream> using namespace std; // Recursive function to sort an array using // insertion sort void insertionSortRecursive(int arr[], int n) { // Base case if (n <= 1) return; // Sort first n-1 elements insertionSortRecursive( arr, n-1 ); // Insert last element at its correct position // in sorted array. int last […]
//BINARY SEARCH USING ITERATION #include<iostream> using namespace std; int binarysearch(int a[],int n,int x){ int start=0; int end=n-1; while(start<=end){ int mid=(start+end)/2; if(x==a[mid]) return mid; else if(x<a[mid]) end=mid-1; else start=mid+1; } return -1; } int main(){ int a[]={4,6,8,10,12,14,18,20}; cout<<“enter a number:\n”; int x; cin>>x; int index=binarysearch(a,8,x); if(index!=-1) cout<<“\n number is at index “<<index; else cout<<“\n number not […]
#include<iostream> using namespace std; /* Linked list structure */ struct list { struct list *prev; int data; struct list *next; } *node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL; class linkedlist { public: /* Function for create/insert node at the beginning of Linked list */ void insert_beginning() { […]
#include<iostream> using namespace std; /* Linked list structure */ struct list { struct list *prev; int data; struct list *next; } *node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL; class linkedlist { public: /* Function for create/insert node at the beginning of Linked list */ void insert_beginning() { […]