0% found this document useful (0 votes)
28 views2 pages

to Arrange The Records of A Structure in Ascending Order (Bubble Sort)

This document contains code to sort the records of a structure called "game" in ascending order based on the "score" field. It defines a structure called "game" with fields for game code, name, and score. It includes a function called "bsort" that uses the bubble sort algorithm to sort an array of game structures by score. The main function gets input from the user to populate an array of game structures, calls bsort to sort it, and outputs the sorted array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

to Arrange The Records of A Structure in Ascending Order (Bubble Sort)

This document contains code to sort the records of a structure called "game" in ascending order based on the "score" field. It defines a structure called "game" with fields for game code, name, and score. It includes a function called "bsort" that uses the bubble sort algorithm to sort an array of game structures by score. The main function gets input from the user to populate an array of game structures, calls bsort to sort it, and outputs the sorted array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

//To arrange the records of a structure in ascending order(bubble sort)

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct game
{ int gcode;
char gname[20];
float score;
};
void bsort(game g[10],int size)
{ game temp;
int i,j;
for(i=0;i<size;i++)
{for(j=0;j<size-1-i;j++)
{if(g[j].score>g[j+1].score)
{temp=g[i];
g[i]=g[j+1];
g[j+1]=temp;
}
}
}
cout<<"gcode\tgname\tscore\n";
for(i=0;i<size;i++)

cout<<g[i].gcode<<"\t"<<g[i].gname<<"\t"<<g[i].score<<endl;
}
void main()
{ clrscr();
game g[10];
int size,i;
cout<<"Enter size of array";
cin>>size;
cout<<"Enter array element";
for(i=0;i<size;i++)
{cout<<"Enter gcode";
cin>>g[i].gcode;
cout<<"Enter gname";
gets(g[i].gname);
cout<<"Enter score";
cin>>g[i].score;
}
bsort(g,size);
getch();
}

You might also like