Merge sort...My problem

I have linked list and struct like this...
struct list{
float price;
float password;
char name[20];
}

User writes price and names in linked list. I have sorted linked list with merge sort by price... My problem is-> When user write 2 equal price then program must sort sort this equal price by name...How to do this? I sorted by price...This is sort for price...

From linked list i have move price to int array[] and this is first argument for merge sort...How to implement name to sort 2 equal prices if user write this?

numbers ->float array (price)t
temp -> empty array
polje_sifra -> this is passwor but this is not important..I use this for better sorting...


void merge(float numbers[], float temp[],float polje_sifra[], int left, int mid, int right)
{
float *temp2 = new float[br_unesenih_el(glava)];
int i, left_end, num_elements, tmp_pos;

left_end = mid - 1;
tmp_pos = left;
num_elements = right - left + 1;

while ((left <= left_end) && (mid <= right))
{
if (numbers[left] <= numbers[mid])
{
temp[tmp_pos] = numbers[left];
temp2[tmp_pos] = polje_sifra[left]; //to
tmp_pos = tmp_pos + 1;
left = left +1;
}
else
{
temp[tmp_pos] = numbers[mid];
temp2[tmp_pos] = polje_sifra[mid];
tmp_pos = tmp_pos + 1;
mid = mid + 1;
}
}

while (left <= left_end)
{
temp[tmp_pos] = numbers[left];
temp2[tmp_pos] = polje_sifra[left];
left = left + 1;
tmp_pos = tmp_pos + 1;
}
while (mid <= right)
{
temp[tmp_pos] = numbers[mid];
temp2[tmp_pos] = polje_sifra[mid];
mid = mid + 1;
tmp_pos = tmp_pos + 1;
}

for (i=0; i <= num_elements; i++)
{
numbers[right] = temp[right];
polje_sifra[right] = temp2[right];
right = right - 1;
}
}
void m_sort(float numbers[], float temp[],float polje_sifra[], int left, int right)
{
int mid;

if (right > left)
{
mid = (right + left) / 2;
m_sort(numbers, temp, polje_sifra, left, mid);
m_sort(numbers, temp,polje_sifra, mid+1, right);

merge(numbers, temp, polje_sifra, left, mid+1, right);
}
}
void mergeSort(float numbers[], float temp[], float polje_sifra[], int array_size)
{
m_sort(numbers, temp, polje_sifra, 0, array_size - 1);
}
Topic archived. No new replies allowed.