Sort the students of a class who have opted for Bus pass, based on their register numbers using Bubble sort. (Register numbers should be alpha numeric

Leave a Comment
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>


struct bus{
char name[30],reg[10];
}a[100];


int n;

int uniq(struct bus a[],int n,char t[])
{
int i,flag=1;
for(i=0;i {
if(strcmpi(a[i].reg,t)==0)
{
flag =0;
break;
}
}
return flag;
}




void sort(struct bus a[],int n)
{
int i,j;
struct bus t;
for(i=0;i {
for(j=0;j {
if(strcmpi(a[j].reg,a[j+1].reg)>0)
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}


void input(struct bus a[],int n)
{
int i;
char t[10];
printf("\nEnter detaila of student 1");
printf("\nEnter student name:");
fflush(stdin);
gets(a[0].name);
printf("\nEnter the reg number:");
gets(a[0].reg);
system("cls");

for(i=1;i<n;i++)


system("cls");
printf("\nEnter for student %d",i+1);
printf("\nEnter the name:");
fflush(stdin);
gets(a[i].name);
x: printf("\nEnter the reg number:");
fflush(stdin);
gets(t);
if(uniq(a,i,t))
strcpy(a[i].reg,t);
else
{
printf("\nReenter the reg number!!!");
goto x;
}
}
}


void print(struct bus a[],int n)
{
int i;
for(i=0;i {
printf("\nDetails of student %d",i+1);
printf("\nName=%s",a[i].name);
printf("\nreg number=%s",a[i].reg);
}
}



int main()
{
printf("\nEnter the max limit:");
scanf("%d",&n);
input(a,n);
sort(a,n);
print(a,n);
getche();
}

0 comments: