Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Priority Linked Lists? (http://www.go4expert.com/forums/priority-linked-lists-t10076/)

tr3molo 16Apr2008 19:32

Priority Linked Lists?
 
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

tr3molo 17Apr2008 17:09

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
Code:

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

main()
{

IORB *list1, *list2, *list3,*list4,*list5, *head, *temp;
           
head=NULL;
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;

head=list1;
temp = head;

list_size=length(head);
printf("%i",list_size);

print_list(head);
sort(head);
print_list(head);

system("pause");
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


All times are GMT +5.5. The time now is 07:29.