Posts

Showing posts from March, 2018

Kruskal’s algorithm C++

Image
 Kruskal’s algorithm C++ Add caption #include<iostream> #include<conio.h> #include<stdlib.h> using namespace std; int cost[10][10],i,j,k,n,m,c,visit,visited[10],l,v,count,count1,vst,p; main() { int dup1,dup2; cout<<"enter no of vertices"; cin >> n; cout <<"enter no of edges"; cin >>m; cout <<"EDGE Cost"; for(k=1;k<=m;k++) { cin >>i >>j >>c; cost[i][j]=c; cost[j][i]=c; } for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(cost[i][j]==0) cost[i][j]=31999; visit=1; while(visit<n) { v=31999; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(cost[i][j]!=31999 && cost[i][j]<v  && cost[i][j]!=-1 ) { int count =0; for(p=1;p<=n;p++) { if(visited[p]==i || visited[p]==j) count++; } if(count >= 2) { for(p=1;p<=n;p++) if(cost[i][p]!=31999 && p!=j) ...

c++ linked list

Image
c++ linked list #include<bits/stdc++.h> using namespace std; struct node     {         int x,*p;         struct node *next;     }; void addNode(struct node *ptr)     {         int i;         cout<<"Enter the value of x[x>0]";         cin>>i;         if(i<=0)         {             ptr->next=NULL;         }         else         {            struct node *temp=(struct node*)malloc(sizeof(struct node));            ptr->x=i;            ptr->next=temp;            addNode(ptr->next);         }     } ...

Menu C++

Image
Menu C++ Add caption #include<bits/stdc++.h> using namespace std; void insertFunction(); void deleteFunction(); void displayFunction(); void exitFunction(); int stackArray[100]; int topIndex = -1, item =0; int main() {     while(1)     {         system("cls");         printf("Enter your choice: \n1. Insert/Push\n2. Delete/POP\n3. Display\n4. Exit\n\n");         int a;         scanf("%d",&a);         switch(a)         {         case 1:             insertFunction();             break;         case 2:             deleteFunction();             break;         case 3:       ...