|
|
#1 (permalink) | |
|
Monster Member
Join Date: Nov 2006
Location: Merrylands 2160
Age: 21
Posts: 3,687
Rep Power: 6
|
Quote:
|
|
|
|
|
|
|
|
|
#2 (permalink) |
|
Contributing Member
Join Date: Jun 2006
Posts: 607
Rep Power: 3
|
It looks like the important considerations are priority, in place, and testing... and explaining design. :P
From the question we get a couple of things 1) The OS may have more then one IO Scheduling strategy it can use. And it can pick and choose which one to use depending on various factors, this makes a lot of sense, and you should try to understand why. 2) You have to write a sort() function. And you know the arguments for this will be the head of the IORB list (struct iorb_item* head) or something of the like. and the second argument will be a function pointer to the function which returns a priority value. ( which could be, conceivably something like this: int (*priFunc)(* struct iorb_item_t)) 3) it has to be sorted IN PLACE, due to various other requirements within the OS to access items in this list, you should not be creating new iorb_items! just changing the order of the linked list (next for a singly linked list and prev and next for a double) 4) Test Test Test!!!
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this into your signature. |
|
|
|
|
|
#3 (permalink) |
|
Contributing Member
Join Date: Jun 2006
Posts: 607
Rep Power: 3
|
Oh yes, you also may want to think about why you have to sort it in place, i.e. what would happen if you didn't and started creating new IORB's and deleting the old ones? (kaboom/kernel panic, but why?)
Its probable that they expect you to elaborate on why the scheduling policy would be adaptive, and why it needs to be in place when you talk about the design.
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this into your signature. |
|
|
|
|
|
#4 (permalink) |
|
Monster Member
Join Date: Nov 2006
Location: Merrylands 2160
Age: 21
Posts: 3,687
Rep Power: 6
|
Ok i understand that. I was talking with the teacher and she said that if i do not implement that priority **** i will lose 1 mark.
This is my current code: Code:
# include <stdio.h>
# include <stdlib.h>
typedef struct iorb {
short base_pri;
struct iorb *link;
char filler[110];
} IORB;
struct node{
int inputData;
struct node *next;
};
typedef struct node node;
node * head,*save,*current;
void displayList (struct node *pList)
{
struct node *h;
h = pList;
printf("List Content: \n");
if(pList!= NULL)
{
do
{
printf("%d\n",h->inputData);
h=h->next;
} while (h!= pList);
}
else
printf("List content is EMPTY\n");
}
void sort_list(struct node *pList){
/*Code for bubble sort alrogithm for a Array
Bubble sort will check int X against intX+1.
If int X is > then int X + 1 then switch
else leave it as it is and then do the next int*/
struct node *h;
int temp;
h = pList;
current = save = h;
if (pList==NULL)
{
printf("\aLinked List Is Empty!\n");
}
else
{
printf("Well ok list isnt empty, now sort");
}
}
struct node *insert(struct node *pList, int input){
struct node *h;
if(pList==NULL){
pList=(struct node *)malloc(sizeof(struct node));
if(pList==NULL) {
printf("Unable to Allocate Memory\n");
}
pList-> inputData = input;
pList-> next = pList;
} else {
h = pList;
while (h-> next != pList)
h = h-> next;
h-> next = (struct node *)malloc(sizeof(struct node));
if(h -> next == NULL){
printf("Unable to Allocate Memory!\n");
}
h = h-> next;
h-> inputData = input;
h-> next = pList;
}
return (pList);
}
|
|
|
|
|
|
#5 (permalink) |
|
GotGames Moderator
Join Date: Jun 2006
Location: Vic
Posts: 2,060
Rep Power: 5
|
A) Write out the algorithm in psuedo-code
B) Write a new, out-of-context example in C, and test it with some numbers C) Implement it in your project Why are you bubble sorting? Its like the slowest way around! Insertion sort or shell sort for the win! Nice demonstrations here.
__________________
"If you wanna get it through their head, talk to them ragely" - fakeh Last edited by ivo; 18-04-2008 at 11:53 AM.. |
|
|
|
|
|
#6 (permalink) |
|
Monster Member
Join Date: Nov 2006
Location: Merrylands 2160
Age: 21
Posts: 3,687
Rep Power: 6
|
Ive got the pseudo code. Ive got the code ive used to bubble sort an array. Just implementing into this list **** is proving a mission. Ive got my code so far and this is it:
Code:
struct node *sort_list(struct node *pList){
struct node *h, *oneUp;
int temp;
h = oneUp = pList;
for (pList=h;(pList != NULL);pList=pList->next)
{
for (oneUp=pList->next;(oneUp != NULL);oneUp=oneUp->next)
{
if ( pList->inputData < oneUp->inputData ){
temp = oneUp->next;
oneUp->next = pList->next;
pList->next = temp;
}
}
}
return (pList);
}
Bubble sort is slow but thats what we have to use :/ I dont know why its not working... |
|
|
|
|
|
#7 (permalink) |
|
GotGames Moderator
Join Date: Jun 2006
Location: Vic
Posts: 2,060
Rep Power: 5
|
I haven't done C/struts, so I can't help you much with the syntax.
Since it seems you've been trying to get a sorting alogrithm right for the past x hours, I'd recommend taking a deep breath, try as hard as you possibly can to forget everything you've just done, and start from scratch from the psuedo-code. Get the logic back, rather than keep your brain filled with code. And to me, that looks like an insertion sort, not a bubble.
__________________
"If you wanna get it through their head, talk to them ragely" - fakeh |
|
|
|
|
|
#8 (permalink) |
|
Contributing Member
Join Date: Jun 2006
Posts: 607
Rep Power: 3
|
Hey,
Ok I think what is happeing is that the syntax of C is confusing you. What Ivo has said is a really good idea. Go back to psuedo-code and hammer out a solution. it also looks like the only struct you need to worry about is 'struct iorb', or IORB (same thing, ...mostly) So you get a HEAD which is an IORB which points to a next IORB (through link) something like this (if there are 3 or more in the list) void my_function(IORB *head) { printf("I am the first IORB %x\n", head); printf("I am the second IORB %x\n", head->link); printf("I am the third IORB %x\n", head->link->link); }
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this into your signature. |
|
|
|




