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 of Flood fill algorithm

  2. Program to illustrate the implementation of Rotation Transformation

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

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

  5. Program that provides an example of This pointer

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

  7. Program to construct Lagrangess Interpolation Formula from the given distinct data points.

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

  9. Program that provides an example of passing objects to function using call by reference method

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

  11. Program to draw a Polygon

  12. Program to illustrate the implementation of 3D Rotation Transformation along x-axis

  13. Program to add pairs of MxN matrices

  14. Weather Temperature Recording Project

  15. Program that takes 10 integer from a user and perform addition using class

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

  17. Program to illustrate the Selection Sort

  18. Program that places n equally spaced points on the circumference of a circle of radius r,and then join each point to every other point

  19. Program to fill different types of geometric shapes using Flood Fill Algorithm (Using Linked-List)

  20. Program to draw a Sphere using Parametric Equations

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