C++ Programming Tutorial

 
 
 

Data File Structure Programs

Array

Insert, edit, delete, append, display, Srch. Insert, delete, merge, delete multiple occurrences Arrays as a Stack in graphics

Stack

Stack operations using array Stack using static memory allocation Stack using dynamic memory allocation Double ended link list as a stack Lnked list as a Stack Infix expr. to Postfix expr. Postfix expr. into an Infix expr. Arrays as a Stack in graphics Stack as an Arithmetic expr. Evaluater Graphical Rep. of Stack Stack to traverse - inodr, postodr, preodr

Queue

Queue using static memory allocation Queue using dynamic memory allocation Circular queue Linked list as a Queue Double Ended linked list as a Queue Graphical Rep. of Queue Arrays as a Linear Queue Array as a Circular Queue Arrays as a Linear Queue ( in graphics ) Arrays as a Circular Queue ( in graphics )

Linked List

Singly link list Circular linked list Doubly link list Linked list as a Queue Linked list as a Stack Double Ended linked list as a Queue Double Ended linked list as a Stack Infix to Postfix - Linked List as Stack Circular doubly link list Single Ended Linked List - Sorting in both odr Hashing - double ended Linked List Sort of link list

Tree

Linked List as a Binary Srch. Tree Set Class using Binary Srch. Tree Maximum depth of Binary Srch. Tree Minimum Spaning Tree Prims algo - minimum spanning tree Traverse binary tree - inodr, preodr, post Find number in binary Srch. tree display levell

Sorting

Bubble Sort Selection Sort Insertion Sort Radix Sort Merge Sort Quick Sort Heap Sort Linear Sort Shell Sort Topological Sort

Searching

Linear Srch. or Sequential Srch. Binary Search Breadth First Search Traversal Depth First Search Traversal Shortest Path-Given Source-Destination-Dijkstras

Hashing

Simple implementation of Hashing Hashing using double-ended Linked List Hashing using Mid-Square Method Example of Hashing n term of the fibonacci series using recursion

Recursion

Factorial of the given number using recursion Mystery of Towers of Hanoi using recursion
 
 

Image

//Heap sort

#include <iostream.h>
#include <conio.h>

class heap
{
int k[11],size;
public:
void getdata(void);
friend void create_heap(heap &);
friend void sort_heap(heap &);
void showdata(void);
};

void heap :: getdata(void)
{
clrscr();
cout<<\"Enter the size of Array :-\";
cin>>size;
cout<<\"\\nEnter \"<<size<<\" Elements\\n\";
 for(int i=1;i<=size;i++) //Creating heap from  index1 instead of index0
   cin>>k[i];
}

void heap :: showdata(void)
{
  clrscr();
  cout<<\"\\n\\nHeap Function Output\\n\\n\";
  for(int i=1;i<=size;i++)
    cout<<k[i]<<endl;
}


void create_heap(heap &a)
{
int q,i,j,key;
  for(q=2;q<=a.size;q++)
  {
    i=q;
    key=a.k[i];
    j=i/2;
    while(i>1 && key>a.k[j])
      {
         a.k[i]=a.k[j];
         i=j;
         j=i/2;
         if(j<1)
            j=1;
      }
    a.k[i]=key;
    }
}

void sort_heap(heap &a)
{
int q,i,j,key,temp;
  for(q=a.size;q>=1;q--)
  {
     temp=a.k[1];
     a.k[1]=a.k[q];
     a.k[q]=temp;
     i=1;
     key=a.k[i];
     j=2*i;
     if(j+1 < q)
     {
         if(a.k[j+1] > a.k[j])
            j++;
        }
     while(j<=q-1 && key<a.k[j])
     {
       a.k[i]=a.k[j];
       i=j;
       j=2*i;
       if(j+1 < q)
       {
          if(a.k[j+1] > a.k[j])
             j++;
       }
       else
           break;
     }
     a.k[i]=key;
    }
}

void main()
{
heap o1;
o1.getdata();
create_heap(o1);
sort_heap(o1);
o1.showdata();
getch();
}

    Related Post:
  1. Program to show the 3D Shearing Transformation along y-axis

  2. Program to estimate value of First Derivative of the function at the given points from the given data using Backward Difference Formula , Forward diff

  3. Program to show the 3D Reflection Transformation along xy-plane

  4. Program of reflection in x axis

  5. Program to show the Urdu Alphabets using Stroke Method

  6. Program that defines template of vector class that provides modify and multiplication facility

  7. Program of Education System that maintains Institute Database using multilevel inheritance

  8. Program to read a Non-Linear equation in one variable, then evaluate it using Secant Method and display its kD accurate root

  9. Write a function power() to raise a number m to a power n

  10. Program that performs addition of 2 matrix using friend function

  11. Program to open file

  12. Program to construct Clamped Cubic Spline Interpolant from the given data

  13. Program to illustrate supplying of values to pointer variables

  14. Program that prints the first 10 integers(using for loop)

  15. Program to display numeric triangle for user given value

  16. Program to show the projection of 3D objects using Standard Perspective Projection w.r.t. an Arbitrary Plane and Center of Projection...

  17. Program for converting string to class object

  18. Program to show the projection of 3D objects using Orthographics Parallel Projection w.r.t. xy-plane and along vector v

  19. Program to illustrate the binary operator(*) overloading without creating a new object

  20. Program to sort that set of strings in ascending and descending order of their weights. The sorted output is to be displayed on the screen

 
 
Didn't find what you were looking for? Find more on Program to perform heap sort