1. 数组a[i], 求数组output,其中output[i]=product(a[j] | j!=i)
void f(int *a, int *output, int n) { for(int i=0;i<n;i++) { output[i] = 1; } int left = 1, right = 1; for(int i=0;i<n;i++) { output[i] *= left; output[n-1-i] *= right; left *= a[i]; right *= a[n-1-i]; } }
2. 非递归遍历二叉树
void inorder(node* root) { stack<node*> s; node *current = root; while(!s.empty()||current) { if(current) { s.push(current); current = current->left; } else { current = s.top(); s.pop(); cout<<current->data<<endl; current = current->right; } } }