0
저는 직원 데이터 구조체가 있고 이름과 성 필드가 두 개로 구분됩니다. 나는이 배열을 이름으로 정렬하고 싶다. 2 개의 이름이 같은 경우에는 성으로 정렬한다. 나는 이미 배열을 첫 번째 이름으로 정렬했으나 여전히 두 번째 이름이 같은 경우 마지막 이름으로 배열을 수행합니다. array.sort()와 같은 내장 함수를 사용하지 않고이 종류를 구현하고 싶습니다. 루프를 사용하고 싶습니다.C# - 루프를 사용하여 내장 함수를 사용하지 않고 구조체 배열 정렬
public struct EmployeeData
{
public char sex;
public int age;
public int id1;
public int id2;
public int id3;
public string fname;
public string lname;
public int seniority;
}
static EmployeeData[] SortByFirstName(EmployeeData[] empdata)
{
int min = 0;
EmployeeData temp;
for (int i = 0; i < empdata.Length; i++)
{
for (int j = i+1; j < empdata.Length; j++)
{
if (empdata[i].fname.Length < empdata[j].fname.Length)
{
min = empdata[i].fname.Length;
}
else
{
min = empdata[j].fname.Length;
}
for (int k = 0; k < min; k++)
{
if (empdata[i].fname[k] > empdata[j].fname[k])
{
temp = empdata[i];
empdata[i] = empdata[j];
empdata[j] = temp;
break;
}
else if (empdata[i].fname[k] == empdata[j].fname[k])
{
continue;
}
else
{
break;
}
}
}
}
return empdata;
}
당신을 위해 내 솔루션 작업을했다? –