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 that takes input of 2 matrix rows and columns data and displays addition of it using + operator overloading

  2. Program to show the Urdu Alphabets using Stroke Method

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

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

  5. CREATING A CLASS ACCOUNTS FROM WHICH ARE DERIVED TWO CLASSES CURRENT AND SAVINGS AND THEN ASK THE USER FOR THE TYPE OF ACCOUNT HE WANTS TO CREATE

  6. Problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs

  7. Program to illusrate data conversion b/w built-in data types and user defined data types (int & float)

  8. Program to illustrate the Radix Sort

  9. Program to print an array before and after adding 5 to its contents using pointers

  10. Program to show the implementation of Bottom-Up Parsing

  11. Program of constructor overloading

  12. Program of Minimum Spaning Tree ( MST )

  13. Program of heap sort

  14. Program to convert an Infix Expression into a Postfix Expression

  15. Program to show the projection of 3D objects using Cabinet Oblique Parallel Projection onto xy-plane (i.e. angle=30 deg)

  16. Program to calculate distance summation, subtraction, multiplication and comparison using overloading operators also make it friend functions

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

  18. Program to illustrate an example of structures

  19. Program of reflection in x axis

  20. Program that provides facilities of calculator in c++

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