当前位置: 首页>>代码示例>>Java>>正文


Java StdIn.isEmpty方法代码示例

本文整理汇总了Java中edu.princeton.cs.algs4.StdIn.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java StdIn.isEmpty方法的具体用法?Java StdIn.isEmpty怎么用?Java StdIn.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.princeton.cs.algs4.StdIn的用法示例。


在下文中一共展示了StdIn.isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    ResizingArrayStack<String> stack = new ResizingArrayStack<String>();
    while (!StdIn.isEmpty()) {
        String item = StdIn.readString();
        if (!item.equals("-")) stack.push(item); 
        else if (stack.isEmpty())  StdOut.println("BAD INPUT"); 
        else                       StdOut.print(stack.pop() + " ");
    }
    StdOut.println();

    // print what's left on the stack
    StdOut.print("Left on stack: ");
    for (String s : stack) {
        StdOut.print(s + " ");
    }
    StdOut.println();
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:18,代码来源:ResizingArrayStack.java

示例2: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    ResizingArrayQueue<String> q = new ResizingArrayQueue<String>();
    while (!StdIn.isEmpty()) {
        String item = StdIn.readString();
        if (!item.equals("-")) q.enqueue(item); 
        else if (q.isEmpty())  StdOut.println("BAD INPUT"); 
        else                       StdOut.print(q.dequeue() + " ");
    }
    StdOut.println();

    // print what's left on the stack
    StdOut.print("Left on queue: ");
    for (String s : q) {
        StdOut.print(s + " ");
    }
    StdOut.println();
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:18,代码来源:ResizingArrayQueue.java

示例3: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
/**
*  client program
*  takes a command-line integer k; reads in a sequence of strings from standard input using StdIn.
* readString(); and prints exactly k of them, uniformly at random. Print each item from the sequence at most once.
*/
public static void main(String[] args) {
	int k = Integer.parseInt(args[0]);

	RandomizedQueue<String> queue = new RandomizedQueue<>();
	
	while (!StdIn.isEmpty()) {
		queue.enqueue(StdIn.readString());
	}

	int cnt = -1;

	for (String s : queue) {
		if (++cnt == k)
			break;

		StdOut.println(s);
	}
}
 
开发者ID:DCMMC,项目名称:Java-Algorithms-Learning,代码行数:24,代码来源:Permutation.java

示例4: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    int max = Integer.parseInt(args[0]);
    FixedCapacityStackOfStrings stack = new FixedCapacityStackOfStrings(max);
    while (!StdIn.isEmpty()) {
        String item = StdIn.readString();
        if (!item.equals("-")) stack.push(item); 
        else if (stack.isEmpty())  StdOut.println("BAD INPUT"); 
        else                       StdOut.print(stack.pop() + " ");
    }
    StdOut.println();

    // print what's left on the stack
    StdOut.print("Left on stack: ");
    for (String s : stack) {
        StdOut.print(s + " ");
    }
    StdOut.println();
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:19,代码来源:FixedCapacityStackOfStrings.java

示例5: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    Deque<String> op = new LinkedList<String>();
    Deque<Double> val = new LinkedList<Double>();

    while (!StdIn.isEmpty()) {
        String s = StdIn.readString();
        if (s.equals("(")) ;
        else if (s.equals("+")) op.addFirst("+");
        else if (s.equals("*")) op.addFirst("*");
        else if (s.equals("-")) op.addFirst("-");
        else if (s.equals("/")) op.addFirst("/");
        else if (s.equals(")")) {
            String operator = op.removeFirst();
            Double n1 = val.removeFirst();
            Double n2 = val.removeFirst();
            if (operator.equals("+")) val.addFirst(n1 + n2);
            else if (operator.equals("*")) val.addFirst(n1 * n2);
            else if (operator.equals("-")) val.addFirst(n2 - n1);
            else if (operator.equals("/")) val.addFirst(n2 / n1);
        }
        else val.addFirst(Double.parseDouble(s));      
    }
    System.out.println(val.removeFirst());
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:25,代码来源:Evaluate.java

示例6: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    int max = Integer.parseInt(args[0]);
    FixedCapacityStack<String> stack = new FixedCapacityStack<String>(max);
    while (!StdIn.isEmpty()) {
        String item = StdIn.readString();
        if (!item.equals("-")) stack.push(item); 
        else if (stack.isEmpty())  StdOut.println("BAD INPUT"); 
        else                       StdOut.print(stack.pop() + " ");
    }
    StdOut.println();

    // print what's left on the stack
    StdOut.print("Left on stack: ");
    for (String s : stack) {
        StdOut.print(s + " ");
    }
    StdOut.println();
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:19,代码来源:FixedCapacityStack.java

示例7: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    int k = Integer.parseInt(args[0]);
    RandomizedQueue<String> queue = new RandomizedQueue<>();

    while (!StdIn.isEmpty()) {
        queue.enqueue(StdIn.readString());
    }

    Iterator<String> iterator = queue.iterator();
    for (int i = 0; iterator.hasNext() && i < k; i++) {
        StdOut.println(iterator.next());
    }
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:14,代码来源:Permutation.java

示例8: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    Stack<String> stack = new Stack<>();

    while (!StdIn.isEmpty()) {
        String s = StdIn.readString();
        if (s.equals("-")) StdOut.print(stack.pop());
        else stack.push(s);
    }
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:10,代码来源:Main.java

示例9: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    int N = StdIn.readInt();
    UF uf = new UF(N);

    while (!StdIn.isEmpty()) {
        int p = StdIn.readInt();
        int q = StdIn.readInt();
        if (!uf.connected(p, q)) {
            uf.union(p, q);
            StdOut.println(p + ' ' + q);
        }
    }
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:14,代码来源:Main.java

示例10: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
 In in = new In(args[0]);
  Digraph G = new Digraph(in);
  SAP sap = new SAP(G);
  while (!StdIn.isEmpty()) {
      int v = StdIn.readInt();
      int w = StdIn.readInt();
      int length   = sap.length(v, w);
      int ancestor = sap.ancestor(v, w);
      StdOut.printf("length = %d, ancestor = %d\n", length, ancestor);
  }
}
 
开发者ID:Lxinyuelxy,项目名称:Princeton_Algorithms,代码行数:13,代码来源:SAP.java

示例11: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
	int k = Integer.parseInt(args[0]);
	RandomizedQueue<String> que = new RandomizedQueue<String>();
	
	while(!StdIn.isEmpty()){
		String item = StdIn.readString();
		que.enqueue(item);
	}
	for(int i = 0; i < k; i++){
		StdOut.println(que.dequeue());
	}
}
 
开发者ID:Lxinyuelxy,项目名称:Princeton_Algorithms,代码行数:13,代码来源:Permutation.java

示例12: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
/** Test client.
 * Reads a sequence of strings from the standard input.
 * Builds a symbol table whose keys are the strings read.
 * The value of each string is its position in the input stream
 * (0 for the first string, 1 for the second, and so on).
 * Then prints all the (key,value) pairs.
 */
public static void main(String[] args) {
    LinkedListST<String, Integer> st;
    st = new LinkedListST<>();
    for (int i = 0; !StdIn.isEmpty(); i++) {
        String key = StdIn.readString();
        st.put(key, i);
    }

    StdOut.println("isEmpty(): "+st.isEmpty());
    StdOut.println("get(E)"+st.get("E"));
    StdOut.println("get(\"bola\")"+st.get("bola"));
    StdOut.println("size()"+st.size());
    StdOut.println("rank(E)"+st.rank("E"));
    StdOut.println("Min()"+st.min());
    StdOut.println("max()"+st.max());
    StdOut.println("ceiling(J)"+st.ceiling("J"));
    StdOut.println("floor(J)"+st.floor("J"));
    StdOut.println("select(4)"+st.select(4));
    StdOut.println("deleteMin()");
    StdOut.println("deleteMax()");
    st.deleteMin();
    st.deleteMax();

    for (String s : st.keys())
        StdOut.println(s + " " + st.get(s));
}
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:34,代码来源:LinkedListST.java

示例13: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
/**
 * Unit tests the {@code MinhaRBT} data type.
 *
 * @param args the command-line arguments
 */
public static void main(String[] args) { 
    MinhaRBT<String, Integer> st = new MinhaRBT<String, Integer>();
    for (int i = 0; !StdIn.isEmpty(); i++) {
        String key = StdIn.readString();
        st.put(key, i);
        StdOut.println("Height : "+st.eagerHeight);
    }
    StdOut.println("AvgSearchHit : "+st.averageSearchHit());
    StdOut.println("AvgSearchMiss : "+st.averageSearchMiss());

    StdOut.println("Calculated Height = "+st.height());
    StdOut.println("Calculated size = "+st.size());
    int k = 0;
    for (String s : st.keys()){
        if(k > 10)  break;
        StdOut.println(s + " ");
        k++;
    }



    /*
    for (String s : st.keys())
        StdOut.println(s + " " + st.get(s));
    StdOut.println();
    */
}
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:33,代码来源:MinhaRBT.java

示例14: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    MinhaBST<String, Integer> st = new MinhaBST<>();
    for (int i = 0; !StdIn.isEmpty(); i++) {
        String key = StdIn.readString();
        st.put(key, i);
        StdOut.println("Height : "+st.eagerHeight);
    }
    StdOut.println("AvgSearchHit : "+st.averageSearchHit());
    StdOut.println("AvgSearchMiss : "+st.averageSearchMiss());

    StdOut.println("Calculated Height = "+st.height());
    StdOut.println("Calculated size = "+st.size());

    StdOut.println("Max = "+st.max());
            int k = 0;
    for (String s : st.keys()){
        if(k > 10)  break;
        StdOut.println(s + " ");
        k++;
    }


/*
    for (String s : st.levelOrder())
        StdOut.println(s + " " + st.get(s));

    StdOut.println();

    for (String s : st.keys())
        StdOut.println(s + " " + st.get(s));
*/
}
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:33,代码来源:MinhaBST.java

示例15: main

import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
    int k = Integer.parseInt(args[0]);
    RandomizedQueue<String> rq = new RandomizedQueue<>();
    while(!StdIn.isEmpty())
        rq.enqueue(StdIn.readString());
    for (int i = 0; i < k; i++)
        StdOut.println(rq.dequeue());
}
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:9,代码来源:Subset.java


注:本文中的edu.princeton.cs.algs4.StdIn.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。