Skip to main content

Posts

Showing posts from April, 2022

Heap-Sort(Program)

  Heap-Sort CODE 👇 #include<stdio.h> #include<stdlib.h> void heapsort(int a[], int n); void heapify(int a[], int  i, int last); void buildheap(int a[], int n); void display(int a[], int n); void heapsort(int a[10], int n) { int i,temp; buildheap(a,n); printf("\n   Initialize Heap"); display(a,n); printf("\n"); for(i=n-1; i>=1; i--) { temp=a[0]; a[0]=a[i]; a[i]=temp; printf("\nAfter %d Iteration-->", n-i); display(a,n); //printf("\n"); heapify(a, 0, i-1); } } void buildheap(int a[], int n) { //convert a[0] ... a[n-1] into heap int i; for(i=(n/2)-1; i>=0; i--) heapify(a,i, n-1); } void heapify(int a[], int i, int last) { int j, temp, key; key=a[i]; j=2*i+1; if((j<last )&&(a[j]<a[j+1])) j=j+1; if((j<=last)&&(key < a[j])) { temp = a[i]; a[i] = a[j]; a[j] = temp; heapify(a, j ,last);   } } void display(int a[

Level-Order Travsal BST(Program)

Level-Order Travsal CODE 👇 //Main File #include<stdio.h> #include<stdlib.h> #include "levelorder.h"   void main() {     NODE *root=NULL;     printf("\t>>First Create BST<<\n");     root = createbst(root);       display(root);      printf("\n\n\t>>Level order traversal<<\t");     levelorder(root); } //Header File    #define MAXSIZE 20     typedef struct node     {      int info;      struct node *left, *right;     }NODE;      //QUEUE FUNCTIONS     typedef struct     {      NODE *data[MAXSIZE];      int front, rear;     }QUEUE;     void initq(QUEUE *pq)     {      pq->front = pq->rear = -1;     }     void addq(QUEUE *pq, NODE *treenode)     {      pq->data[++pq->rear] = treenode;     }     NODE* removeq(QUEUE *pq)     {      return pq->data[++pq->front];     }     int isempty(QUEUE *pq)     {      return (pq->front == pq->rear);     }     int isfull(QUEUE