- #1
mathmari
Gold Member
MHB
- 5,049
- 7
Hey!
I want to write a function for the constitution of a star system "ss".
The new star system contains an empty list of planetary system, that means that in the list of the planetary system exists only the sentinel node, and the empty tree of the free-floating planets (ffp). The new star system should be inserted into the array of star systems(StarS). The complexity of the insertion should be $O(1)$.
The structures are the following:
I have the following:
Is it correct?? (Wondering)
What does it mean "in the list of the planetary system exists only the sentinel node"?? (Wondering) How could we do that?? (Wondering)
I want to write a function for the constitution of a star system "ss".
The new star system contains an empty list of planetary system, that means that in the list of the planetary system exists only the sentinel node, and the empty tree of the free-floating planets (ffp). The new star system should be inserted into the array of star systems(StarS). The complexity of the insertion should be $O(1)$.
The structures are the following:
Code:
struct starsy {
int ss; /* The star system identifier. >0 */
plansys_t *plasy; /* Pointer to the first element in the list of the planetary system */
plansys_t *Sentinel; /* Pointer to the sentinel node of the list of the planetary system */
asteroid_t *ff; /* The free-floating planets tree */
};struct plansys {
int solid; /* The planetary system identifier. >0 */
asteroid_t *asteroids; /* Pointer to the first node in the list of the asteroids */
asteroid_t *asentinel; /* Pointer to the sentinel node of the asteroids tree */
plansys_t *next; /* Pointer to the next node in the list of the planetary systemt */
};struct asteroid {
int as; /* The asteroid identifier. >0 */
int gap; /* The absolute gap from the object of the planetary system */
asteroid_t *PARENT; /* Pointer to the parent node in the asteroids tree */
asteroid_t *LC; /* Pointer to the left child in the asteroids tree */
asteroid_t *RC; /* Pointer to the right child in the asteroids tree */
};
starsy_t StarS[N]; /*The array of the star systems, it is an array of lists */
int Sfreep; /*An index to the first free position in the array of the star systems*/
I have the following:
Code:
int Constitution(int ss) {
int i;
starsy_t *starsystem=NULL;
if(Sfreep<N){
starsystem = &StarS[Sfreep];
Sfreep++;
}
if(Sfreep>=N){
return -1;
}
starsystem->ss = ss;
starsystem->plasy=NULL;
starsystem->Sentinel=NULL;
starsystem->ff->as=INT_MAX;
starsystem->ff->gap=INT_MAX;
starsystem->ff->PARENT=NULL;
starsystem->ff->LC=NULL;
starsystem->ff->RC=NULL;
return 0;
}
Is it correct?? (Wondering)
What does it mean "in the list of the planetary system exists only the sentinel node"?? (Wondering) How could we do that?? (Wondering)
Last edited by a moderator: