Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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*/
- asteroid_t *Insert(plansys_t *p, asteroid_t *new) {
- if (p->asteroids == p->asentinel) p->asteroids=new;
- if (new->gap < p->asteroids->gap) {
- if (p->asteroids->LC == p->asentinel){
- p->asteroids->LC = new;
- new->LC=p->asentinel;
- new->RC=p->asentinel;
- }
- else
- Insert(p->asteroids->LC, new);
- }
- if (new->gap > p->asteroids->gap) {
- if (p->asteroids->RC == p->asentinel){
- p->asteroids->RC = new;
- new->LC=p->asentinel;
- new->RC=p->asentinel;
- }
- else
- Insert(p->asteroids->RC, new);
- }
- return p->asteroids;
- }
- void In_Order(plansys_t *p) {
- if (p->asteroids == p->asentinel) return;
- In_Order(p->asteroids->LC);
- printf(" %d , %d n", p->asteroids->as, p->asteroids->gap);
- In_Order(p->asteroids->RC);
- }
- int asteroid_constitution(int as, int gap, int solid) {
- int i, g=0, k=-1;
- plansys_t *p=NULL;
- asteroid_t *plasy_sent=NULL;
- for(i=0; i<Sfreep; i++){
- p=StarS[i].plasy;
- while (p != StarS[i].Sentinel && p->solid != solid){
- p=p->next;
- }
- if(p != StarS[i].Sentinel && p->solid == solid){
- k=i;
- }
- }
- if(k == -1){
- return -1;
- }
- asteroid_t *ast = calloc(1, sizeof(asteroid_t));
- ast->as=as;
- ast->gap=gap;
- ast->PARENT=NULL;
- ast->LC=NULL;
- ast->RC=NULL;
- p=StarS[k].plasy;
- plasy_sent=p->asentinel;
- p->asteroids=Insert(p, ast);
- In_Order(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement