Advertisement
sawyermade

join & issub nigga

Nov 20th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. int join(int t1, int t2) {
  2.     if(isSubtype(t1, t2))
  3.         return t2;
  4.     if(isSubtype(t2,t1))
  5.         return t1;
  6.     return join(classesST[t1].superclass, t2);
  7. }
  8.  
  9. int isSubtype(int sub, int super) {
  10.  
  11.     if(sub == -1 || super == -1)
  12.         return 0;
  13.     if(sub == -2)
  14.         return 1;
  15.     if(sub == super)
  16.         return 1;
  17.     if(sub == 0)
  18.         return 0;
  19.     if(super == -2)
  20.         return 0;
  21.  
  22.     int ar[numClasses];
  23.     memset(ar, 0, sizeof(int)*numClasses);
  24.     while(sub != super) {
  25.         if(ar[sub])
  26.             return 0;
  27.         ar[sub] = 1;
  28.         sub = classesST[sub].superclass;
  29.     }
  30.     return 1;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement