利用栈实现算术表达式求值(Java语言描述) 算术表达式求值是栈的典型应用,自己写栈,实现Java栈算术表达式求值,涉及栈,编译原理方面的知识.声明:部分代码参考自茫茫大海的专栏. 链栈的实现: package 算数表达式求值; public class Stack<T> { //节点类 public class Node{ public T data; public Node next; public Node(){} public Node(T data,Node next){ this.
The area Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1637 Accepted Submission(s): 1298 Problem Description Ignatius bought a land last week, but he didn't know the area of the land because t
关于欧几里得算法求最大公约数算法, 代码如下: int gcd( int a , int b ) { if( b == 0 ) return a ; else gcd( b , a % b ) ; } 证明: 对于a,b,有a = kb + r (a , k , b , r 均为整数),其中r = a mod b . 令d为a和b的一个公约数,则d|a,d|b(即a.b都被d整除), 那么 r =a - kb ,两边同时除以d 得 r/d = a/d - kb/d = m (m为整数,因为r也
破圈法求解最小生成树c语言实现(已验证) 下面是算法伪代码,每一个算法都取一个图作为输入,并返回一个边集T. 对该算法,证明T是一棵最小生成树,或者证明T不是一棵最小生成树.此外,对于每个算法,无论它是否能计算出一棵最小生成树,都要给出其最有效的实现. MAYBE-MST-A(G,w) Sort the edges into nonincreasing order of edge weights w T<-E For each edge e, taken in nonincreasing ord
素数:一个数只能被1和它本身整除的数.2是最小的素数 #include <iostream> using namespace std; #define NUM 100 ]; int main() { //筛选法求素数 //假设所有的素数都是素数,标志位设为1 ; i <= NUM ; i++){ isPrime[i] = ; } // 首先去除当前数的倍数.例如当前数为2,那么去除4,6,8等等 ; i <= NUM ; i++){ if(isPrime[i]){ //将相应的标志
快排法求第k大,复杂度为O(n) import com.sun.media.sound.SoftTuning; import java.util.Arrays; import java.util.Random; public class Main { int[] generate(int n) { Random random = new Random(); int[] a = new int[n]; for (int i = 0; i < a.length; i++) { a[i] = rand
原文地址: http://blog.csdn.net/qustmeng/article/details/52186378?locationNum=4&fps=1 import java.util.LinkedList; import java.util.List; public class Demo { /** * 二次指数平滑法求预测值 * @param list 基础数据集合 * @param year 未来第几期 * @param modu
Atlantis 题目连接 http://poj.org/problem?id=1151 Description here are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describ