Wednesday, May 30, 2012
Monday, May 21, 2012
clear recent project list in netbeans
get hold of user directory from Help->About (menu)
for me it's : C:\Users\admin\.netbeans\7.1.1
Then go to : c/Users/admin/.netbeans/7.1.1/config/Preferences/org/netbeans/modules
edit file : projectui.properties
remove all lines starting with 'recent'
Thursday, May 10, 2012
NetBeans jvi :w problem (colon w)
Tools -> Options -> jVi Config -> Platform
uncheck : ":" Command completion Auto Popup
Wednesday, May 9, 2012
Tuesday, May 8, 2012
Vim : replacing text with matched text
For e.g. If my input is :
$this->Lang("abc");
$this->Lang("kkk");
and I want to make it :
"abc";
"kkk";
then :
:1,$ s/$this->Lang(\(.*\))/\1/
\1 denotes the text matched between first \( \)
Thursday, May 3, 2012
C program for printing all permutations
#include <stdio.h>
void swap(int* a,int i,int j) {
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
void print_array(int* a,int n) {
int i;
for(i = 0; i<= n; ++i) {
printf("%d ",a[i]);
}
printf("\n");
}
void permute(int* a, int i, int n) {
int j;
if(i == n) print_array(a,n);
else {
for(j = i;j <= n; j++) {
swap(a,i,j);
permute(a,i+1,n);
swap(a,i,j);
}
}
}
void main() {
int a[4] = {1,2,3,4};
permute(a,0,3);
}
void swap(int* a,int i,int j) {
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
void print_array(int* a,int n) {
int i;
for(i = 0; i<= n; ++i) {
printf("%d ",a[i]);
}
printf("\n");
}
void permute(int* a, int i, int n) {
int j;
if(i == n) print_array(a,n);
else {
for(j = i;j <= n; j++) {
swap(a,i,j);
permute(a,i+1,n);
swap(a,i,j);
}
}
}
void main() {
int a[4] = {1,2,3,4};
permute(a,0,3);
}
Wednesday, May 2, 2012
rough sketch for generating all permutations
permute(arrayCollection) {
if has only 2 :
AB
BA
else
for ( ith elem in collection) {
otherThanIth = elems other than ith;
otherThanIthPermed = permute(otherThanIth);
prepend(ith, otherThanIthPermed);
}
}
Printing a BST in level order
queue.addAtEnd(root);
queue.addAtEnd(stopper);
while(queue.hasElems() && currNode = queue.popFront()) {\
if(currNode != stopper) {
print currNode;
queue.addAtEnd(left) if left not null;
queue.addAtEnd(right) if right not null;
} else {
print new line;
if queue.hasElems()
addAtEnd(stopper);
}
}
other solutions from leetcode :
With two queues :
void printLevelOrder(BinaryTree *root) {
if (!root) return;
queue<BinaryTree*> currentLevel, nextLevel;
currentLevel.push(root);
while (!currentLevel.empty()) {
BinaryTree *currNode = currentLevel.front();
currentLevel.pop();
if (currNode) {
cout << currNode->data << " ";
nextLevel.push(currNode->left);
nextLevel.push(currNode->right);
}
if (currentLevel.empty()) {
cout << endl;
swap(currentLevel, nextLevel);
}
}
}
With one queue but counters :
void printLevelOrder(BinaryTree *root) {
if (!root) return;
queue<BinaryTree*> nodesQueue;
int nodesInCurrentLevel = 1;
int nodesInNextLevel = 0;
nodesQueue.push(root);
while (!nodesQueue.empty()) {
BinaryTree *currNode = nodesQueue.front();
nodesQueue.pop();
nodesInCurrentLevel--;
if (currNode) {
cout << currNode->data << " ";
nodesQueue.push(currNode->left);
nodesQueue.push(currNode->right);
nodesInNextLevel += 2;
}
if (nodesInCurrentLevel == 0) {
cout << endl;
nodesInCurrentLevel = nodesInNextLevel;
nodesInNextLevel = 0;
}
}
}
Subscribe to:
Posts (Atom)