how to sorting this, i've problem to sort by jum_nilai from the highest until smallest

void lihatData(void)
{
if(pertama==NULL)
        printf("Data tidak ada !!!");
    else
    {
        printf("%3s %-20s %-12s %-5s %-7s %-7s %-5s %-5s\n","No","Nama","Jenis K","N Mtk","N B.Ind","N B.Ing","N IPA","Jumlah");
        printf("--- -------------------- -------------- ------- ------- ------- ----- -----\n");

        sekarang=pertama;

        do
        {
                printf("%3d %-20s %-12s %-5d %-7d %-7d %-5d %-5d\n",\
                sekarang->nomor,\
                sekarang->nama,\
                sekarang->jenis_k,\
                sekarang->nilai1,\
                sekarang->nilai2,\
                sekarang->nilai3,\
                sekarang->nilai4,\
                sekarang->jum_nilai);
        }

        while((sekarang=sekarang->next) != NULL);

    }
}

Recommended Answers

All 6 Replies

type entire prog

AND type in English the messages as wellas the variable name.Its hard to uderstand.

how to sorting this, i've problem to sort by jum_nilai from the highest until smallest

void lihatData(void)
{
    if(pertama==NULL)
       printf("Data tidak ada !!!");
    else
    {
        printf("%3s %-20s %-12s %-5s %-7s %-7s %-5s %-5sn","No","Nama","Jenis K","N Mtk","N B.Ind","N B.Ing","N IPA","Jumlah");
        printf("--- -------------------- -------------- ------- ------- ------- ----- -----n");

        sekarang=pertama;

        do
        {
                printf("%3d %-20s %-12s %-5d %-7d %-7d %-5d %-5dn",
                sekarang->nomor,
                sekarang->nama,
                sekarang->jenis_k,
                sekarang->nilai1,
                sekarang->nilai2,
                sekarang->nilai3,
                sekarang->nilai4,
                sekarang->jum_nilai);
        }

        while((sekarang=sekarang->next) != NULL);

    }
} 

end-quote

what do you mean by sort from highest to smallest? the length of the strings?

also wrap your code in code-tags and post the complete code

And sort by what name?? orNo or anything else??

type entire prog

AND type in English the messages as wellas the variable name.Its hard to uderstand.

if the OP is not english oriented then it's alright if the code itself is not in proper english as long as it is properly formatted and maybe commented on important parts so as to help us pass the language barrier in helping

if the OP is not english oriented then it's alright if the code itself is not in proper english as long as it is properly formatted and maybe commented on important parts so as to help us pass the language barrier in helping


i will sort descending by jum_nilai... how?

use a loop to traverse the linked list then compare the current value to the next to exchange the positions if needed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.