Sunteți pe pagina 1din 1

#include<iostream.

h>
#include<fstream.h>
ifstream f("graf.in");
int n,m;
struct muchie{ int x,y,c;} a[100];
void citire()
{int i;
f>>n>>m;
for(i=1;i<=m;i++)
f>>a[i].x>>a[i].y>>a[i].c;
}
void bubble(muchie a[], int n)
{int sort,i;
muchie aux;
do{ sort=1;
for(i=1;i<n;i++)
if(a[i].c>a[i+1].c)
{aux=a[i];
a[i]=a[i+1];
a[i+1]=aux;
sort=0;}}
while (sort==0);}
void afisare()
{ int i;
for(i=1;i<=m;i++)
cout<<a[i].x<<a[i].y<<" "<<a[i].c<<endl;}
int main()
{citire();
bubble(a,m);
afisare();
}
//in graf.in
7 11
1 2 1
1 7 1
2 3 2
2 7 2
2 3 1
3 5 2
3 7 1
4 5 1
4 7 2
5 6 1
6 7 2