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>
#define ROW 7
#define COL 7
#define infi 5000  //infi for infinity

class prims
{
   int graph[ROW][COL],nodes;
   public:
   prims();
   void createGraph();
   void primsAlgo();
};

prims :: prims(){
     for(int i=0;i<ROW;i++)
       for(int j=0;j<COL;j++)
     graph[i][j]=0;
}

void prims :: createGraph(){
    int i,j;
    cout<<\"Enter Total Nodes : \";
    cin>>nodes;
    cout<<\"\\n\\nEnter Adjacency Matrix : \\n\";
    for(i=0;i<nodes;i++)
        for(j=0;j<nodes;j++)
        cin>>graph[i][j];

    //Assign infinity to all graph[i][j] where weight is 0.
    for(i=0;i<nodes;i++){
        for(j=0;j<nodes;j++){
           if(graph[i][j]==0)
          graph[i][j]=infi;
        }
    }
}

void prims :: primsAlgo(){
    int selected[ROW],i,j,ne; //ne for no. of edges
    int false=0,true=1,min,x,y;

    for(i=0;i<nodes;i++)
       selected[i]=false;

    selected[0]=true;
    ne=0;

    while(ne < nodes-1){
       min=infi;

       for(i=0;i<nodes;i++)
       {
          if(selected[i]==true){
         for(j=0;j<nodes;j++){
            if(selected[j]==false){
               if(min > graph[i][j])
               {
               min=graph[i][j];
               x=i;
               y=j;
               }
            }
         }
          }
       }
       selected[y]=true;
       cout<<\"\\n\"<<x+1<<\" --> \"<<y+1;
       ne=ne+1;
    }
}

void main(){
    prims MST;
    clrscr();
    cout<<\"\\nPrims Algorithm to find Minimum Spanning Tree\\n\";
    MST.createGraph();
    MST.primsAlgo();
    getch();
}

    Related Post:
  1. Program to copy n number of characters from one string to another at position p

  2. PROGRAM FOR ACCEPTING MEASUREMENTS IN METERS AND FEETS AND SUMMING THEM UP IN THE FORMAT THAT THE USER WISHES

  3. Program that provides an example of class, object and constructors

  4. Program that changes an infix expression to a postfix expression according

  5. Program to swap two integers

  6. Program to construct Newtons Backward Difference Interpolation Formula from the given distinct equally spaced data points

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

  8. Program to multiply 2 polynomial functions

  9. Program of Rotate About Origin

  10. Employee database management system

  11. Program of nesting member functions, private member functions and array of objects

  12. Program to draw an Ellipsoid using Parametric Equations

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

  14. Program to convert an Infix Expression into a Postfix Expression using Linked List as a Stack

  15. Program to interchange the values of two int , float and char using function overloading

  16. Program to illustrate the use of call-by-refrence method in functions

  17. Library System

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

  19. Program to show the implementation of Sutherland-Hodgeman Polygon Clipping Algorithm

  20. Develop a Toy Compiler, which takes a series of statements as input, and creates a symbol table from it

 
 
Didn't find what you were looking for? Find more on Prims algorithm for minimum spanning tree