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

 # include <iostream.h>
 # include  <fstream.h>
 # include   <string.h>
 # include    <stdio.h>
 # include    <conio.h>

 /**************************************************************************/
 //---------------------------------  Node  -------------------------------//
 /**************************************************************************/

 class Node
 {
    public:
       int data;

       Node* Next;
 };

 # define MAX_ENTRIES  25

 Node* HashTable[MAX_ENTRIES]={NULL};
 Node* Top[MAX_ENTRIES]={NULL};


 /**************************************************************************/
 //------------------------  generate_hash_key( )  ------------------------//
 /**************************************************************************/

 const int generate_hash_key(const int data)
 {
    return (data%MAX_ENTRIES);
 }

 /**************************************************************************/
 //---------------------------  insert_data( )  ---------------------------//
 /**************************************************************************/

 void insert_data( )
 {
    int data;

    cout<<\"\\n\\n\\n\\t *********   New Element   ********* \"<<endl<<endl;
    cout<<\"\\t Enter a value : \";
    cin>>data;

    int index=generate_hash_key(data);

    Node* Entry=new Node;

    if(!Entry)
    {
       cout<<\"\\n\\n\\n\\t Fatal Error : Unable to allcate memory to stroe new element.\"<<endl;
       cout<<\"\\n\\n\\t\\t Pres any key to return to Menu. \";

       getch( );
       return;
    }

    if(HashTable[index]==NULL)
    {
       Entry->data=data;
       Entry->Next=NULL;
       HashTable[index]=Entry;
       Top[index]=Entry;
    }

    else
    {
       Entry->data=data;
       Entry->Next=NULL;
       Top[index]->Next=Entry;
       Top[index]=Entry;
    }

    cout<<\"\\n\\n\\t\\t Pres any key to return to Menu. \";

    getch( );
 }

 /**************************************************************************/
 //----------------------------  print_data( )  ---------------------------//
 /**************************************************************************/

 void print_data( )
 {
    clrscr( );

    cout<<\"\\n\\n\\t *****  HashTable & Data  *****\\n\"<<endl;

    Node* Print;

    for(int index=0;index<MAX_ENTRIES;index++)
    {
       if(index<10)
      cout<<\"\\t HashTable[0\"<<index<<\"] : \";

       else
      cout<<\"\\t HashTable[\"<<index<<\"] : \";

       Print=HashTable[index];

       if(Print!=NULL)
       {
      while(Print!=NULL)
      {
         cout<<Print->data;

         Print=Print->Next;

         if(Print!=NULL)
        cout<<\" , \";
      }

      cout<<endl;
       }

       else
      cout<<\"-\"<<endl;
    }

    cout<<\"\\n\\n\\t\\t Pres any key to return to Menu. \";

    getch( );
 }

 /**************************************************************************/
 //----------------------------  search_data( )  --------------------------//
 /**************************************************************************/

 void search_data( )
 {
    int data;

    cout<<\"\\n\\n\\n\\t *****  Search an Element  *****\\n\"<<endl;
    cout<<\"\\t Enter a value : \";
    cin>>data;

    int flag=0;
    int index=generate_hash_key(data);

    Node* Print=HashTable[index];

    if(Print!=NULL)
    {
       while(Print!=NULL)
       {
      if(Print->data==data)
         flag++;

      Print=Print->Next;
       }

       if(flag)
      cout<<\"\\n\\n\\t ***  The Search Element is found \"<<flag<<\" times.\";
    }

    if(!flag)
       cout<<\"\\n\\n\\t ***  The Search Element is not found.\"<<endl;

    cout<<\"\\n\\n\\n\\t\\t Pres any key to return to Menu. \";

    getch( );
 }

 /**************************************************************************/
 //---------------------------  show_working( )  --------------------------//
 /**************************************************************************/

 void show_working( )
 {
    char Key=NULL;

    do
    {
       clrscr( );

       gotoxy(10,5);
       cout<<\"**********   Implementation of Hashing   **********\"<<endl;

       gotoxy(10,8);
       cout<<\"Select one of the listed operation :\"<<endl;

       gotoxy(15,10);
       cout<<\"- Press \\\'I\\\' to Insert an Element\"<<endl;

       gotoxy(15,12);
       cout<<\"- Press \\\'P\\\' to Print the HashTable & Data\"<<endl;

       gotoxy(15,14);
       cout<<\"- Press \\\'S\\\' to Search an Element\"<<endl;

       gotoxy(15,16);
       cout<<\"- Press \\\'E\\\' to Exit\"<<endl;

       Input:

       gotoxy(10,20);
       cout<<\"                      \";

       gotoxy(10,20);
       cout<<\"Enter your Choice : \";

       Key=getche( );

       if(int(Key)==27 || Key==\'e\' || Key==\'E\')
      break;

       else if(Key==\'i\' || Key==\'I\')
      insert_data( );

       else if(Key==\'p\' || Key==\'P\')
      print_data( );

       else if(Key==\'s\' || Key==\'S\')
      search_data( );

       else
      goto Input;
    }
    while(1);
 }


 int main( )
 {
    textmode(C4350);

    show_working( );

    return 0;
 }

    Related Post:
  1. Program to illustrate printing data on the printer

  2. Program that reads marks obtained by a student in a test of 100 marks and computes his grade

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

  4. 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....

  5. Program to show the implementation of Hashing with Insert, Delete and search functionality using double-ended Linked List

  6. Program to illustrate over-riding of base class member function in a derived class

  7. Program that prints odd numbers form 0 to 50 (Using for Loop)

  8. Program to construct and display the Divided Difference Table from the given distinct data points.

  9. Program to read a Linear System of Equations,then evaluate it by using Guass-Seidel Itrative Method and show the result

  10. Program to reverse the sequence of the words in the sentence and display the result

  11. File Operation Program

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

  13. Program of scaling about origin

  14. Program to illustrate the implementation of Stack as an Arithmetic Expression Evaluater

  15. Program to illustrate the implementation of Reflection Transformation about the line y=x and y=-x

  16. Program to illustrate use of arrays as data items in classes

  17. Program to perform radix sort

  18. PROGRAM THAT PROVIDES AN EXAMPLE OF GETLINE FUNCTION

  19. Program to generate a triangular wave form according to a specified pair of Amplitude and Frequency

  20. Program to illustrate the implementation of 3D Rotation Transformation along y-axis

 
 
Didn't find what you were looking for? Find more on Program to show the Simple implementation of Hashing