Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

sorting array of struct

$
0
0

hey why code is not able to sort on the basis of "e" when the inputs are : 100 4,4 5,200 6,2 5

//JUST PRACTISING

#include<cstdio>
#include<iostream>
#include<list>
#include<vector>
#include<utility>
using namespace std;
struct node
{
    int u;
    int w;
}road[10];

int comp(node a,node b)
{
    if(a.u<b.u)
    return a.u;
    else
    return b.u;

}

int main()
{
    for(int i=0;i<4;i++)
    {  int a,b;
        scanf("%d%d",&road[i].u,&road[i].w);
    }

     sort(road,road+4,comp);
 printf("\n\n\n\n");
    for(int i=0;i<4;i++)
    {
        printf("%d   %d\n",road[i].u,road[i].w);
    }

    system("pause");
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>