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 <conio.h>
# include <process.h>

int display_menu();
int array_no=1; //CURRENT ARRAY 1 OR 2
class array
{
 int arr[20];
 int n;
 public:
    array()
    {
     n=0;
    }
    void add_n(int);
    int getval(int);
    int getsize();
    void getelements();
    void display();
    void insert();
    void delete_element();
    void merge_array(array);
};

int array :: getsize()
{
 return n;
}
void array :: add_n(int x)
{
 n=n+x;
}
int array :: getval(int i)
{
 return (arr[i]);
}
void array :: getelements()
{
  cout<<\"Enter Number of elements you want to enter :\";
  cin>>n;
  for(int i=0;i<n;i++)
  {
   cout<<\"a[\"<<i<<\"] :=>\";
   cin>>arr[i];
  }
}

void array :: display()
{
  cout<<endl;
  if(n==0)
  {
   cout<<endl<<\"No Element !!!\"<<endl;
  }

  for(int i=0;i<n;i++)
  {
    cout<<\"a[\"<<i<<\"] :\"<<arr[i]<<endl;
  }
}

void array :: insert()
{
  display();
  int pos;
  cout<<endl<<\"[Enter Number Between 0 \"<<\"And \"<<n<<endl;;
  cout<<endl<<\"Enter Position Where you want to Insert :\";
  cin>>pos;
  if(pos < 0 || pos >n)
  {
   cout<<\"Out of Range !!!\";
  }
  else
  {
  for(int i=n;i>pos;i--)
  {
   arr[i]=arr[i-1];
  }
  cout<<\"Enter Number :\";
  cin>>arr[pos];
  cout<<\"Number Inserted at the Position \"<<pos<<endl;
  n=n+1;
  }
}

void array :: delete_element()
{
  display();
  //Delete Multiple Occurance of a Number in an Array
  int no,i,pos,j;
  cout<<endl;
  cout<<\"Enter Number to Delete :\";
  cin>>no;

  for(i=0;i<n;i++)
  {
   pos=i;
   if(arr[i]==no)
   {
    for(j=pos;j<n-1;j++)
    {
     arr[j]=arr[j+1];
    }
    n=n-1;
    i--;
   }
  }
}

void array :: merge_array(array a1)
{
  for(int i=0;i<a1.getsize();i++)
  {
    arr[i+n]=a1.getval(i);
  }
  add_n(a1.getsize());
  cout<<\"Second Array merged with current array ...\";
}






void main()
{
 clrscr();
  array a1,a2;
 int arr_no;
 while(1)
 {
 switch(display_menu())
 {
  case 1: cout<<\"Select Array  [ 1 Or 2 ]\";
      cin>>arr_no;
      if(arr_no==1 || arr_no==2)
      {
       array_no=arr_no;
      }
      else
      {
       cout<<\"Invalid Number entered !!!!\";
       getch();
      }
      break;
  case 2 : if(array_no==1)
       {
        a1.getelements();
       }
       else
       {
        a2.getelements();
       }
       break;
  case 3 : if(array_no==1)
       {
         a1.insert();
       }
       else
       {
         a2.insert();
       }
       getch();
       break;
  case 4 : if(array_no==1)
       {
         a1.delete_element();
       }
       else
       {
        a2.delete_element();
       }
       getch();
       break;

  case 5 : if(array_no==1)
       {
        a1.display();
       }
       else
       {
        a2.display();
       }
       getch();
       break;









  case 6 : if(array_no==1)
       {
         a1.merge_array(a2);
       }
       else
       {
         a2.merge_array(a1);
       }
       getch();
       break;
  case 7 : exit(1);
 }
 }
}

int display_menu()
{
  int ch;
  clrscr();
  cout<<endl<<\"\\t\\t\\t[ Current Array is :\"<<array_no<<\"]\"<<endl;
  cout<<\"\\t\\t\\t| 1 | - Select Array\"<<endl;
  cout<<\"\\t\\t\\t| 2 | - Enter Elements\"<<endl;
  cout<<\"\\t\\t\\t| 3 | - Insert\"<<endl;
  cout<<\"\\t\\t\\t| 4 | - Delete\"<<endl;
  cout<<\"\\t\\t\\t| 5 | - Display\"<<endl;
  cout<<\"\\t\\t\\t| 6 | - Merge Second Array\"<<endl;
  cout<<\"\\t\\t\\t| 7 | - Exit\"<<endl;
  cout<<\"\\t\\t\\tEnter Your Choice :\";
  cin>>ch;
  return(ch);
}

    Related Post:
  1. Code for finding a no in a binary search tree and displaying its level where it is found (root is at zero level)

  2. Program to fill different types of geometric shapes using Flood Fill Algorithm

  3. Program to estimate the value of Third Derivative of the function at the given points from the given data using Central Difference Formula of Order 4

  4. Program to implement the Kurskals Algorithm to solve Minimum Cost Spanning Tree Problem (MST)

  5. Program to show the implementation of None-or-All Character Clipping Strategy (Text Clipping Example)

  6. Program to draw a circle using MidPoint Circle Algorithm

  7. Program to implement the Prims Algorithm to solve Minimum Spanning Tree Problem (MST)

  8. Program that provides an example of friend function of a class

  9. Program of that provides an example of function overloading

  10. Program to fill different types of geometric shapes using Boundary Fill Algorithm

  11. Program to illustrate the passing of values to constructor in classes

  12. Program to illustrate operator overloading from class to basic type

  13. Program to illustrate the use of friend classes

  14. Program to draw an Elliptical Arc using Trigonometric Method

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

  16. Program to draw a line using Cartesian Slope-Intercept Equation [ Simple Implementation ]

  17. Prims algorithm for minimum spanning tree

  18. Program to show the implementation of Cohen-Sutherland MidPoint Subdivision Line Clipping Algorithm

  19. Program to estimate the Differential value of the function using Euler Method

  20. Program to illustrate the operations that can be performed on pointers