this one has had me stuck for a few days and I am wondering if it is my idea of what is happening here that is askew...
Code:
typedef struct node *node_ptr;
struct node {
char *name;
int n_students;
struct student students[1000];
node_ptr next;
}
struct student {
int ID;
char *name;
}
I have the structure working with nodes (which correspond with units the students enrol in) and they are sorted alphabetically on insertion.... but
I'm having a hard time when I insert students to figure how to insert them in order by ID. I mean given student 1 is and ID of 123 and student 2 is 155 - what should I be doing as a general strategy to insert ID 139 for example.
My strategy so far was to find the place it fit and then attempt to shuffle the rest up one and insert the student... which doesn't seem to work. Is this the wrong way. My issue is related to not understanding the rules perhaps - "can I" shuffle the rest of these struct members along and insert in the right spot or is there a trick to it?
I haven't posted code yet as I'm at this point hoping my understanding of the general idea might improve. It is also a uni assignment (although I am 42yo) and I don't particularly just want to put up code here or get out of the box answers unless I have to to gain that understanding. I somehow dont' understand this one.
could anyone offer some advice?