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 that reads a number ,coumputes and displays its factorial using do-while loop

  2. Library Management System

  3. Program to implement Add and Subtract function on Big Number Class

  4. Program that provides an example of destructors

  5. Simple Inventory Program

  6. Program that computes and display the sum of first ten integers. (using for loop)

  7. Program to illustrate the binary operator(-) overloading without creating an object of that class

  8. Program of swapping numbers using pointers

  9. Program of virtual inheritance that takes input of staff members and performs an operation on it

  10. Program to draw a Polygon

  11. Program that provides an example to return an object from a function

  12. Program to illustrate unary operator increment operator overloading with return type

  13. Program of disk editor

  14. Program that displays graphical representation of tower of hanoi

  15. Program to calculate distance summation, subtraction, multiplication and comparison using overloading operators also make it friend functions

  16. Implement a Matrix class representing 2-dimensional matrix with the following functionalities i.e. operators + , - , * , == , += &lt;&lt; , &gt;&gt; etc

  17. Program to illustrate the implementation of Rotation Transformation along a Pivot Point

  18. Program that list of letters should be an alphabetical list of upper case letters followed by an alphabetical list of lower case letters

  19. Program to illustrate object initialization and assignment by default member wise copy

  20. Program that reads in a matrix and checks if it has the parity property

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