Priority Linked Lists?

Discussion in 'C' started by tr3molo, Apr 16, 2008.

  1. tr3molo

    tr3molo New Member

    Apr 16, 2008
    Likes Received:
    Trophy Points:
    Hello World, i just started learning the ropes of Linked lists. I get the basic gist of it. Although i am baffled with a question that i clearly do not understand.

    here is the main question:

    You are rerquired to write a C program on Linux which design, implement and test a
    function: sort list(), which will sort such a list according to the priority value computed by
    whatever function is passed as its second argument. The frst argument is to be a pointer
    to the head of the list. Since the OS will have other structures with pointers to IORB's,
    the list must be sorted in place.

    within this question i am given this snippet

    typedef struct iorb {
    short base_pri;
    struct iorb *link;
    char filler[110];
    } IORB;

    OK so this is what i do not understand:

    1. What is char filler[110] used for?
    2. Obviously base_pri means prioity but what exactly is it used for? comparing IORBS?
    3. The Bubble sort is easy to implement, but what argument besides *head must i pass?

    What i do know is a have to build a linked list to simulate disk I/O in systems programming.
    but it is pretty difficult witout first understanding what the question is actually asking of me.

    any suggestions will be appreciated. and any non-suggestions also :)

    thanks in advance - tr3molo
  2. tr3molo

    tr3molo New Member

    Apr 16, 2008
    Likes Received:
    Trophy Points:
    Re: New Fix

    Ok World i have figured it out. But now i have a new problem. I have searced these forums and cannot find a solid solution to my problem. Basically i have to you a bubble sort to sort out my linked lists using the base_pri values. My code looks some what like this
    [COLOR=Blue]typedef struct iorb 
               short base_pri;
               struct iorb *next;
               char filler[110];
          } IORB;[/COLOR]
    IORB *list1, *list2, *list3,*list4,*list5, *head, *temp;
    int list_size;
    list1 = (IORB*)malloc(sizeof(IORB));
    list2 = (IORB*)malloc(sizeof(IORB));
    list3 = (IORB*)malloc(sizeof(IORB));
    list4 = (IORB*)malloc(sizeof(IORB));
    list5 = (IORB*)malloc(sizeof(IORB));
    list1->base_pri = 2;
    list1->next = list2;
    list2->base_pri = 6;
    list2->next = list3;
    list3->base_pri = 1;
    list3->next = list4;
    list4->base_pri = 5;
    list4->next = list5;
    list5->base_pri = 9;
    list5->next = head;
    temp = head;
    return 0;
    as you can see i didnt use a For loop to generate mt lists. The thing now is to build a bubble sort that compares the base_pri. this for me is difficult, because i cannt just cheaply switch the data values, rath chage where each node is pointing to.

    i'm really hoping someone may be able to help, as ive been stuck for a while now.

    cheers in advance tr3molo
    Last edited by a moderator: Apr 17, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice