Tower of Hanoi

Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1) Only one disk can be moved at a time.2) Each move consists of taking the upper disk from one of... Continue Reading →

Quick Sort

#include<stdio.h> void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int partition(int arr[], int p , int q) { int x= arr[p]; int i= p; for(int j=p+1;j<=q;j++) { if(arr[j]<x) { i++; swap(&arr[i],&arr[j]); } } swap(&arr[p],&arr[i]); return i; } void QuickSort(int arr[],int p, int q) { if(p<q) {... Continue Reading →

Merge Sort

#include<stdio.h> void mergesort(int a[],int i,int j); void merge(int a[],int i1,int j1,int i2,int j2); int main() { int a[30],n,i; printf("Enter no of elements:"); scanf("%d",&n); printf("Enter array elements:"); for(i=0;i<n;i++) scanf("%d",&a[i]); mergesort(a,0,n-1); printf("\nSorted array is :"); for(i=0;i<n;i++) printf("%d ",a[i]); return 0; } void mergesort(int a[],int i,int j) { int mid; if(i<j) { mid=(i+j)/2; mergesort(a,i,mid); //left recursion mergesort(a,mid+1,j); //right... Continue Reading →

Generating Random numbers in a given range.

#include <stdio.h> #include <stdlib.h> int main() { int num, randomnum; printf("Enter the number of random numbers you want to enter: \n"); scanf("%d",&num); printf("%d Random no. b/w to 10-99: \n",num); while (num--) { randomnum=rand()%90+10; printf("%d\n",randomnum); } getch(); return 0; }

Insertion sort

This program also calculates the time taken by the insertion sort function to run using time() functions. In this program the user generates random numbers using the rand() function in an array and then applies insertion sort to it. Large input is taken in order to get some value of the time taken by the... Continue Reading →

Linked Lists

Menu Driven Program For All Operations #include <stdio.h> #include <iostream> #include <limits.h> #include <stdlib.h> #include <bits/stdc++.h> using namespace std; struct node { int data; struct node *next; }; struct header { float avg; int max1,min1,max2,min2,totalnode; struct node *next; }; void headerfunc(struct header *); void insertf(struct header *); void deletef(struct header *); void bubble_sort(struct header *);... Continue Reading →

Arrays

Menu Driven Program For All Operations #include <stdio.h> #include <iostream> #include <limits.h> #include <stdlib.h> using namespace std; void insert(int *ar,int*n); void deletef(int *ar,int*n); void bubble_sort(int *ar,int*n); void display(int *ar,int*n); void avg(int *ar,int*n); void max_min(int *ar,int*n); void max2_min2(int *ar,int*n); void disp_odd(int *ar,int*n); void disp_even(int *ar,int*n); int main(void) { int n=0,ar[1000],i=0,c=0; cout<<"Enter size of array(max. 999) :... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started