importjava.util.ArrayList;importjava.util.List;// 聊天室服务器,作为中介者classChatRoom{privateList<User> users =newArrayList<>();// 用户加入聊天室publicvoidregisterUser(User user){users.add(user);user.setChatRoom(this);System.out.println(user.getName()+" has joined the chat room.");}// 用户离开聊天室publicvoidunregisterUser(User user){users.remove(user);System.out.println(user.getName()+" has left the chat room.");}// 发送消息给所有用户publicvoidbroadcast(User sender,String message){for(User user : users){if(!user.equals(sender)){user.receive(sender.getName()+": "+ message);}}}}// 用户(同事类)classUser{privateString name;privateChatRoom chatRoom;publicUser(String name){this.name = name;}publicStringgetName(){return name;}publicvoidsetChatRoom(ChatRoom chatRoom){this.chatRoom = chatRoom;}// 用户发送消息publicvoidsend(String message){chatRoom.broadcast(this, message);}// 用户接收消息publicvoidreceive(String message){System.out.println(this.name +" received: "+ message);}}// 聊天室客户端模拟publicclassChatRoomDemo{publicstaticvoidmain(String[] args){ChatRoom chatRoom =newChatRoom();User user1 =newUser("Alice");User user2 =newUser("Bob");User user3 =newUser("Charlie");chatRoom.registerUser(user1);chatRoom.registerUser(user2);chatRoom.registerUser(user3);// Alice 发送消息user1.send("Hello everyone!");// Bob 发送消息user2.send("Hi Alice, how are you?");// Charlie 离开聊天室chatRoom.unregisterUser(user3);// Alice 再次发送消息,Charlie 不再接收user1.send("Charlie, are you there?");}}
将看到如下输出:
Alice has joined the chat room.
Bob has joined the chat room.
Charlie has joined the chat room.
Bob received:Alice:Hello everyone!Charlie received:Alice:Hello everyone!Alice received:Bob:HiAlice, how are you?Charlie received:Bob:HiAlice, how are you?Charlie has left the chat room.
Bob received:Alice:Charlie, are you there?
1.二叉树的最近公共祖先
解题思路:方法一: 1.先判断p或者q 是不是 root当中的一个
2.左子树当中递归査找p或者q
3.右子树当中递归查找p或者q
如何查找: root 的 left 和 right 都不为空 ->root
root的 left 为空 right 不为空->right这一侧找…
好久没在官网下载 mysql server 安装包。今天想下载发现:
我访问mysql官网的速度好慢啊。mysql server 的下载页面在哪里啊,一下两下找不到。
最后,慢慢悠悠终于找到了下载页面,如下:
https://dev.mysql.com/downlo…