Skip to main content

Posts

Selection Sort

/**     Program Name: Selection Sort     Description: This Program sort a given array elements, using Selection                    Sort Algorithm     Author:  Tauqirul Haque         */ #include <conio.h> #include <stdio.h> #define MAX 5 void selectionSort(int *, int ); void display(int *); void main() {     int array[MAX] = { 35,56,23,11,46 };         printf("\nThe Array Before Sortint .... \n");     display(array);         selectionSort(array,MAX);         printf("\n\nThe Array After Sorting .. \n");     display(array);     } void selectionSort(int *array, int array_size) {   int i, j;   int min, temp;   for (i = 0; i < array_size-1; i++)   {     min = i;     for (j = i+1; j < array_size; j++)     {       if (array[j] < array[min])         min = j;     }     temp = array[i];     array[i] = array[min];     array[min] = temp;   } } void display(int *array) {     int i;     printf("\n&
Recent posts

SWAP Two Values without using temporary variable

/**     Program Name: Swap Two Numbers     Description: This Program swaps two number, using XOR     Author:  Tauqirul Haque        */ #include <stdio.h> #include <conio.h> int main() {     int firstNumber, secondNumber;        printf("Enter The First Number :  ");     scanf("%d",&firstNumber);        printf("\nEnter The Second Number :  ");     scanf("%d",&secondNumber);        printf("\n\nNumbers Before Swapping :  %d  <-> %d \n",firstNumber, secondNumber);        firstNumber = firstNumber^secondNumber;     secondNumber = firstNumber^secondNumber;     firstNumber = firstNumber^secondNumber;        printf("\nNumbers After Swapping :   %d  <->  %d \n",firstNumber, secondNumber);    }

BIT AND Operation

/**     Program Name: AND Operation Between To Binary Numbers     Description: This Program Converts A Decimal Number to its Binary                        Equivalent, using shift Operator, and also performs the                       "logical And" operation between them, and displays output.                      Author:  Tauqirul Haque         */ void printBinary(int i); int main() {     int number, number2;     printf("Enter The Number : ");     scanf("%d",&number);         printf("Enter The Number : ");     scanf("%d",&number2);         printf(" \nA  =    :  ",number);     printBinary(number);         printf(" \nB  =    :  ",number);     printBinary(number2);         printf("\n==================================================");         printf(" \n\nA & B   :  ");     printBinary(number & number2);     printf("\n=============================

Insertion Sort

/**     Program Name: Insertion Sort     Description: This Program Sorts an Array using Insertion Sort Algorithm     Author:  Tauqirul Haque        */  #include <stdio.h> #include <conio.h> #define MAX 10 void insertionSort(int []); void displayArray(int []); void main() {     int array[MAX] = {-999, 78,3,567,99,34,65,34,12, 55};  //this first element is the sentinel        printf("\nThe Element Before Sorting .. ");     displayArray(array);        insertionSort(array);        printf("\nThe Element After Sorting ... ");     displayArray(array);        getch(); } void insertionSort(int array[MAX]) {     int i;     for(i=2;i     {         int ptr = i-1;         int temp = array[i];                while(temp < array[ptr])         {             array[ptr+1]= array[ptr];             ptr--;         }         array[ptr+1] = temp;     } } void displayArray(int array[MAX]) {     printf("\n");     fo

Tower of Hanoi

        /**     Module Name: Tower of Hanoi     Description: This Program is done using Recursion     Author:  Tauqirul Haque     */ void towerOfHanio(int, char, char, char);  int main() {     clrscr();     int disk ;     printf("Enter The Number of Disk :  ");     scanf("%d",&disk);         int move = (int)(pow(2,disk)-1);     printf("\nTotal Number of Moves are #  %d \n",move);             towerOfHanio(disk, 'A','C','B');  // a= source, c = destination , b = temp         printf("\n");     return 0;     } void towerOfHanio(int disk, char source, char destination, char temp) {     if(disk == 1)     {         printf("Move :  %c -> %c",source,destination);     }     else     {         towerOfHanio(disk-1, source, temp, destination);         printf("\nMove :  %c -> %c \n",source,destination);         towerOfHanio(disk-1, temp, destination, source);     }

STACK Using Linked List

/**     Program Name: STACK     Description: This Program Implements Stack using Linked List     Author:  Tauqirul Haque         */     struct StackLinkedList {     int item;     char name[30];     struct StackLinkedList *next; }; typedef struct StackLinkedList node; void push(node **); void pop(node **); void display(node **); void main() {     node *top = NULL;     int choice, item;         while(choice != 4)     {         printf("\n\t\t\t1. Push Element");         printf("\n\t\t\t2. Pop Element ");         printf("\n\t\t\t3. Display Stack");         printf("\n\t\t\t4. Exit Program");                 printf("\nEnter Your Choice #  ");         scanf("%d",&choice);                 switch(choice)         {             case 1 :                     push(&top);                     break;             case 2:                     pop(&top);                     break;        

STACK Using Linear Array

/**     Program Name: STACK     Description: This Program implements Stack Data Structure using Linear Array     Author:  Tauqirul Haque         */         #define SIZE 5 int stack[SIZE]; int top = -1; // this is the initial condition void push(); void pop(); void display(); int main() {     int choice;     while(choice != 4)     {         printf("\n\t\t\t1. Push an Element ");         printf("\n\t\t\t2. POP an Element");         printf("\n\t\t\t3. Display The Stack");         printf("\n\t\t\t4. Exit Program");                 printf("\nEnter Your Choice #  ");         scanf("%d",&choice);                 switch(choice)         {             case 1:                     push();                     break;             case 2:                     pop();                     break;                                 case 3:                     display();                     break;