Java implementation stack class (synchronized mutex)

From , 3 Years ago, written in Java, viewed 213 times.
URL https://pastebin.vip/view/e94550c9
  1. class Stack {
  2.         int idx = 0; // 堆栈指针的初始值为0
  3.         char[] data = new char[6]; // 堆栈有6个字符的空间
  4.  
  5.         public void push(char c) {
  6.                 synchronized (this) { // this表示Stack的当前对象
  7.                         data[idx] = c;
  8.                         idx++;
  9.                 }
  10.         }
  11.  
  12.         public char pop() {
  13.                 synchronized (this) { // this表示Stack的当前对象
  14.                         idx--;
  15.                         return data[idx];
  16.                 }
  17.         }
  18.  
  19. }
  20.  

Reply to "Java implementation stack class (synchronized mutex)"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website