/**
 * Company
 * Copyright (C) 2014-2017 All Rights Reserved.
 */
package com.cwenao.trying.stackandqueue;

import java.util.Stack;

/**
 *
 * @author cwenao
 * @version $Id CelebrityProblemByStack.java, v 0.1 2017-10-03 12:59 cwenao Exp $$
 */
public class CelebrityProblemByStack {

    private static final int[][] MARKED = {{0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 0}, {0, 0, 1, 0}};

    private boolean isKnown(int a, int b) {
        return MARKED[a][b] == 1;
    }

    public int findCelebrity(int n) {
        Stack<Integer> stack = new Stack<>();
        int c;

        for (int i = 0; i < n; i++) {
            stack.push(i);
        }
        while (!stack.isEmpty() && stack.size() > 1) {

            int a = stack.pop();
            int b = stack.pop();
            if (isKnown(a, b)) {
                stack.push(b);
            } else {
                stack.push(a);
            }
        }
        c = stack.pop();

        for (int i = 0; i < n; i++) {

        }

    }

}

@@ -392,16 +392,23 @@
 private 
+static 
 boolean 
@@ -483,16 +483,23 @@
  public 
+static 
 int find
@@ -984,25 +984,291 @@
 ) %7B%0A
-%0A        %7D%0A%0A    %7D%0A
+            if (i != c && (isKnown(c, i) %7C%7C !isKnown(i, c))) %7B%0A                return -1;%0A            %7D%0A        %7D%0A        return c;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        int n = 4;%0A        System.out.println(%22The celebrity index is : %22 + findCelebrity(n));%0A    %7D
 %0A%7D%0A

update the celebrity problem