From 342a10f5d2846345380e7b201d7392e6a5333111 Mon Sep 17 00:00:00 2001 From: suchit1999 <45621996+suchit1999@users.noreply.github.com> Date: Mon, 14 Oct 2019 19:24:04 +0530 Subject: [PATCH 1/2] Create krushkal.c --- Data Structures/Tree/krushkal.c | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Data Structures/Tree/krushkal.c 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]; + } +} From 3969b63b15029c00016fb54fa46706d877d42fd0 Mon Sep 17 00:00:00 2001 From: suchit1999 <45621996+suchit1999@users.noreply.github.com> Date: Mon, 14 Oct 2019 19:28:22 +0530 Subject: [PATCH 2/2] Create BubbleSorting.cpp --- Algorithms/sorting/BubbleSorting.cpp | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Algorithms/sorting/BubbleSorting.cpp 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; + } +}