---
# System prepended metadata

title: 黃智輝 線上測驗

---

# 黃智輝 線上測驗

FROM Teacher T 
INNER JOIN Class C
INNER JOIN Student S
ON T.teacher_id = C.teacher_id AND
C.studnet_id = S.student_id;
ORDER BY C.Class_Name ASC;

```java=
public class Teacher{
// 用private限制建立新老師
 private Teacher(){}
// 先建好
 private static Teacher t = NULL;
  Publics static Teacher callTeacher() {
    if(t == NULL) {
      t = new Teacher();
      return t;
    }else return t;

  }
}
```

Sorting 
```python=
list = [3,2,1,5]

flag = False

for i in range(len(list)):
  flag = False
  for j in range(0,len(list)-i):
    if(list[j] < list[i]):
      temp = list[i];
      list[i] = list[j]
      list[j] = temp
      flag = True
  if(flag == False) break;

[2,3,1,5]
[2,1,3,5]
[1,2,3,5]

壞: O(N^2)
好: O(N)
```

```python=
def sort(list,rev):
  flag = False
  
  for i in range(len(list)):
    flag = False
    for j in range(0,len(list)-i):
      # 升覓
      if(rev == True):
        if(list[j] < list[i]):
          temp = list[i]
          list[i] = list[j]
          list[j] = temp
          flag = True
      # 降覓
      else:
        if(list[j] > list[i]):
          temp = list[i]
          list[i] = list[j]
          list[j] = temp
          flag = True
    if(flag == False) break;
    
  return list
```

大樓5層，單一電梯。電梯怎麼運作。
```java=
class Evalator implement Observable{
  
  //目前哪一樓
  private int floor;
  public Queue<Integer> Upqueue = new Queue();
  public Queue<Integer> Downqueue = new Queue();
  public bool UpDownstatus;
  
  public up(int targetFloor){
    move();
  };
  public down();
  public stay();
  
  public move(int targteFloor){
    
  }
  
  public notify(int targetFloor){
    if(tagetFloor > self.floor) self.down();
    else if (tagetFloor < self.floor) self.up();
    else self.stay();
  }
  
  public move(){
    while(self.queue != NULL){
      int tagetFloor = self.queue.pop();
      self.notfy(targetFloor);
    }
  }
  
  public addQueue(int targetFloor, bool upDown){
    if(upDown != NULL){
      if(upDown == True){
        self.Upqueue.push(targteFloor);
      }else{
        self.Downqueue.push(targetFloor);
      }
    }else{
      if(targetFloor > self.floor){
        self.Upqueue.push(targteFloor);
      }else{
        self.Downqueue.push(targetFloor);
      }
    }
    // self.queue.push(targteFloor);
  }
  // 1 4 5 1
  // 1 5 4 1  (移動)
  
  public initEvalator(bool upDown,int targetFloor){
    if(self.Upqueue == NULL && self.DownQueue== NULL){
      self.UpDownstatus = upDown;
      self.addQueue(targetFloor,upDown);
    }else{
      self.addQueue(targetFloor,upDown);
    }
  }
}

class User() implement Observer{
  private int floor;
  
  //外面
  public void pushBottom(Evaluator e,bool upDown){
    e.initEvalator(bool updown,self.floor);
  }
  
  //裡面
  public move(Evaluator e,int targetFloor){
    e.addQueue(tagetFloor);
  }
  
}
Evaluator evalator = new Evalator();
class main1(){
  public static void main(){
    
     User user = new user(1);
    // 電梯會下樓 到 1樓
    
    // user.move(evalator,5);
    //呼叫到自己樓層
    user.pushBottom(evalator,True);
    user.move(evalator,5);
    
    //電梯 3 -> 1 (接) -> 4 (接) -> 5 (到)
    //電梯 3 -> 1 (接user1) -> 進電梯 按5 - >4 (接user2)
  }
}

class main2(){
  public static void main(){
    
    User user = new user(4);
    
 
    // 電梯會下樓 到 1樓
    user.pushBottom(evalator);
    user.move(evalator,1);
    
    //電梯 3 -> 1 (接) -> 4 (接) -> 5 (到)
    //電梯 3 -> 1 (接user1) -> 5 - >4 (接user2)
  }
}
```

