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 find the distance between two points in 2D and 3D space using function overloading

  2. Program to show the implementation of Cohen-Sutherland Line Clipping Algorithm

  3. Program to illustrate the difference between the use of strcomp, strcmpi and stricmp

  4. Program to illusrate data conversion user defined data types using constructor

  5. Program to display DFA

  6. Program to draw an ellipse using Polynomial Method

  7. Program that takes input of 2 matrix rows and columns data and displays addition of it using + operator overloading

  8. Program to draw a Rectangle

  9. Program to illustrate the implementation of linked list as a Stack

  10. Program to find largest element of an array

  11. Program that take font and background color and text input from a user and display it in center aligned

  12. Program that performs binary search

  13. Program to help Umar in this task. Represent each city by one lowercase character. Thus, you can have at most 26 different cities to visit....

  14. Program of that provides an example of function overloading

  15. Program that reads an expression consisting of two non-negative integer and an operator. Determine if either integer or the result of the expres......

  16. Program to find largest integer among the three and display it using function with no return type

  17. Program that performs file read, write, update and display operations

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

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

  20. Program to illustrate classes without using inline functions

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