{"size": 833, "ext": "js", "max_stars_repo_path": "src/Stack.js", "max_stars_repo_name": "kennetpostigo/dastructs", "max_stars_repo_stars_event_min_datetime": "2016-08-15T22:17:02.000Z", "max_stars_repo_stars_event_max_datetime": "2016-08-15T22:17:02.000Z", "max_issues_repo_path": "src/Stack.js", "max_issues_repo_name": "kennetpostigo/dastructs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Stack.js", "max_forks_repo_name": "kennetpostigo/dastructs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 16.3333333333, "max_line_length": 57, "alphanum_fraction": 0.5870348139}
//  @flow

class StackNode {
  data: any;
  next: ?StackNode;

  constructor (data: any) {
    this.data = data;
    this.next = null;
  }
}

export class Stack {
  top: ?StackNode;
  size: number;
  next: any;
  pop: Function;
  push: Function;
  peek: Function;
  isEmpty: Function;

  constructor () {
    this.size = 0;
    this.top = null;
  }

  pop (): ?StackNode {
    if (!this.top) return null;
    var temp: any = this.top.data;
    this.top = this.top.next;
    this.size--;
    return temp;
  }

  push (element: StackNode): void {
    var stackElement: StackNode = new StackNode(element);
    stackElement.next = this.top;
    this.top = stackElement;
    this.size++;
  }

  peek (): ?StackNode {
    if (!this.top) return null;
    return this.top.data;
  }

  isEmpty (): boolean {
    return this.size === 0;
  }
}
