diff --git a/Algorithms/sorting/BubbleSorting.cpp b/Algorithms/sorting/BubbleSorting.cpp new file mode 100644 index 0000000..967ee48 --- /dev/null +++ b/Algorithms/sorting/BubbleSorting.cpp @@ -0,0 +1,34 @@ +#include +#include +void bubble_sorting(int [],int); +void main() +{ + int a[50]; + int n; + cout<<"enter how many numbers you will be sort"; + cin>>n; + cout<<"enter the values\n"; + for(int i=0;i>a[i]; + bubble_sorting(a,n); + double b[5]={5.8,6.8,9.3,2.6,4.5}; + bubble_sorting(b,n); + cout<<"the sorted array is:-\n "; + for(i=0;i void bubble_sorting(x *a,int size) +{ + int round,i; + x temp; + for(round=0;rounda[i+1]) + { + temp=a[i]; + a[i]=a[i+1]; + a[i+1]=temp; + } +} diff --git a/Data Structures/Tree/krushkal.c b/Data Structures/Tree/krushkal.c new file mode 100644 index 0000000..6df3d51 --- /dev/null +++ b/Data Structures/Tree/krushkal.c @@ -0,0 +1,69 @@ +#include +#include +int root[10],flag=0,count=0,temp,min; +int a[20],cost[20][20],n,i,j,k,totalcost=0,x,y; +void find_min(),check_cycle(),update(); +void main() +{ + clrscr(); + printf("Enter the number of vertices please\n"); + scanf("%d",&n); + printf("Enter the cost of the matrix please\n"); + for (i=1;i<=n;i++) + for (j=1;j<=n;j++) + scanf ("%d",&cost[i][j]); + find_min(); + while (min!=999 && count!=n-1) + { + check_cycle(); + if (flag) + { + printf ("%d ---> %d = %d\n",x,y,cost[x][y]); + totalcost+=cost[x][y]; + update(); + count++; + } + cost[x][y]=cost[y][x]=999; + find_min(); + } + if (countcost[i][j]) + { + min = cost[i][j]; + x = i; + y = j; + } +} +void update() +{ + if(root[x]==0 && root[y]==0) + root[x]=root[y]=x; + else if(root[x]==0) + root[x]=root[y]; + else if(root[y]==0) + root[y]=root[x]; + else + { + temp = root[y]; + for(i=1;i<=n;i++) + if(root[i]==temp) + root[i]=root[x]; + } +}