public Node getMinOfSubTree(Node n) { if (n.Left == null && n.Right == null) return n; Node t = n; while (t.Left != null) { t = t.Left; } return t; }
Sunday, December 27, 2009
Minimum of Binary Sub Tree
Maximum of Binary Sub Tree
public Node getMaxOfSubTree(Node n) { if (n.Left == null && n.Right == null) return n; Node t = n; while (t.Right != null) { t = t.Right; } return t; }
Next Smaller Node
public Node getNextSmaller(Node r)
{
Node t = root;
Node gp = root;
Node p = root;
t = root;
while (t != null && !r.Equals(t))
{
gp = p;
p = t;
if (r.CompareTo(t) < 0)
{
t = t.Left;
}
else
{
t = t.Right;
}
}
if (t.Data == this.getMin()) return null;
if (t.Left == null && p.Data < t.Data) return p;
if (t.Left == null && p.Data > t.Data) return gp;
if (t.Left != null && t.Left.Right != null)
{
t = t.Left.Right;
while (t.Right != null)
{
t = t.Right;
}
return t;
}
if (t.Left != null && t.Left.Right == null) return t.Left;
return null;
}
Next Greater Node
public Node getNextGreater(Node n)
{
Node t = null;
Node p = root;
t = root;
Node gp = null;
while (t != null && !n.Equals(t))
{
gp = p;
p = t;
if (n.CompareTo(t) < 0)
{
t = t.Left;
}
else
{
t = t.Right;
}
}
if (n.Data == this.getMax()) return null;
if (t.Right == null && t.Equals(p.Right)) return gp;
if (t.Right == null && t.Equals(p.Left)) return p;
if (t.Right.Left == null && t.Right.Right == null) return t.Right;
if (t.Right.Left != null) return t.Right.Left;
return null;
}
Tuesday, December 15, 2009
Count words in a sentence
public int countWords(string s1)
{
int cnt = 0;
//char space = ' ';
int i = 0;
for (i = 0; i < s1.Length; i++)
{
if (s1[i] == ' '){}
else if (s1[i] != ' ' && i == 0) cnt++;
else if (s1[i] != ' ' && s1[i - 1] != ' ') { }
else if (s1[i] != ' ' && s1[i - 1] == ' ') cnt++;
}
return cnt;
}
{
int cnt = 0;
//char space = ' ';
int i = 0;
for (i = 0; i < s1.Length; i++)
{
if (s1[i] == ' '){}
else if (s1[i] != ' ' && i == 0) cnt++;
else if (s1[i] != ' ' && s1[i - 1] != ' ') { }
else if (s1[i] != ' ' && s1[i - 1] == ' ') cnt++;
}
return cnt;
}
Thursday, November 5, 2009
Find files and folder in Windows Vista.
It becomes really hectic to find files in windows vista. It does not search in the folders if you don't have the ownership. It becomes a problem if you have a USB hard drive and you plug it in different computers.
You can download it from here:-
http://www.esnips.com/doc/3ba518f7-6341-476f-98a7-ae2cae8b8454/Find
You can download it from here:-
http://www.esnips.com/doc/3ba518f7-6341-476f-98a7-ae2cae8b8454/Find
Saturday, October 17, 2009
ListWmiNamespaces.ps1
# This is a example taken from the book "Microsoft Windows Powershell Step by step"
$wmi = Get-WmiObject -class __Namespace -namespace root
"Listing namespaces on " + $wmi[0].__server +
" please wait a second "
for ($i=0;$i -le $wmi.length;$i++)
{if ($i -lt $wmi.length)
{Write-Host -noNewLine "."
Start-Sleep -m 75}
else
{Write-Host "."}
}
$wmi | Format-List name
Write-Host -foregroundColor green "There are" $wmi.length `
"namespaces on this machine `n"
$wmi = Get-WmiObject -class __Namespace -namespace root
"Listing namespaces on " + $wmi[0].__server +
" please wait a second "
for ($i=0;$i -le $wmi.length;$i++)
{if ($i -lt $wmi.length)
{Write-Host -noNewLine "."
Start-Sleep -m 75}
else
{Write-Host "."}
}
$wmi | Format-List name
Write-Host -foregroundColor green "There are" $wmi.length `
"namespaces on this machine `n"
GetCPUinfo.ps1
# This is a example taken from the book "Microsoft Windows Powershell Step by step"
$wmi = get-wmiObject win32_processor
if ($wmi.Architecture -eq 0)
{"This is an x86 computer"}
elseif($wmi.architecture -eq 1)
{"This is an MIPS computer"}
elseif($wmi.architecture -eq 2)
{"This is an Alapha computer"}
elseif($wmi.architecture -eq 3)
{"This is an PowerPC computer"}
elseif($wmi.architecture -eq 6)
{"This is an IPF computer"}
elseif($wmi.architecture -eq 9)
{"This is an x64 computer"}
else
{$wmi.architecture + " is not a cpu type I am familiar with"}
"Current clockspeed is : " + $wmi.CurrentClockSpeed + " MHZ"
"Max clockspeed is : " + $wmi.MaxClockSpeed + " MHZ"
"Current load percentage is: " + $wmi.LoadPercentage + " Percent"
"The L2 cache size is: " + $wmi.L2CacheSize + " KB"
$wmi = get-wmiObject win32_processor
if ($wmi.Architecture -eq 0)
{"This is an x86 computer"}
elseif($wmi.architecture -eq 1)
{"This is an MIPS computer"}
elseif($wmi.architecture -eq 2)
{"This is an Alapha computer"}
elseif($wmi.architecture -eq 3)
{"This is an PowerPC computer"}
elseif($wmi.architecture -eq 6)
{"This is an IPF computer"}
elseif($wmi.architecture -eq 9)
{"This is an x64 computer"}
else
{$wmi.architecture + " is not a cpu type I am familiar with"}
"Current clockspeed is : " + $wmi.CurrentClockSpeed + " MHZ"
"Max clockspeed is : " + $wmi.MaxClockSpeed + " MHZ"
"Current load percentage is: " + $wmi.LoadPercentage + " Percent"
"The L2 cache size is: " + $wmi.L2CacheSize + " KB"
DisplayComputerRoles.ps1
# This is a example taken from the book "Microsoft Windows Powershell Step by step"
$wmi = get-wmiobject win32_computersystem
"computer " + $wmi.name + " is: "
switch ($wmi.domainrole)
{
0 {"`t Stand alone workstation"}
1 {"`t Member workstation"}
2 {"`t Stand alone server"}
3 {"`t Member server"}
4 {"`t Back up domain controller"}
5 {"`t Primary domain controller"}
default {"`t The role can not be determined"}
}
$wmi = get-wmiobject win32_computersystem
"computer " + $wmi.name + " is: "
switch ($wmi.domainrole)
{
0 {"`t Stand alone workstation"}
1 {"`t Member workstation"}
2 {"`t Stand alone server"}
3 {"`t Member server"}
4 {"`t Back up domain controller"}
5 {"`t Primary domain controller"}
default {"`t The role can not be determined"}
}
Sunday, October 11, 2009
RTR record keeping application
Just a small RTR record keeping application. It uses xml. You just need to download and run it. Thats all. Built on C# 2008.
Download it from:-
http://www.esnips.com/doc/23b9e54d-e3ec-4e14-bb85-72d81523beee/RTRApplication1
Download it from:-
http://www.esnips.com/doc/23b9e54d-e3ec-4e14-bb85-72d81523beee/RTRApplication1
Wednesday, October 7, 2009
Function to test whether 2 array of objects are equal or not.
public static bool AreEqual(object[] o1, object[] o2)
{
if (o1 == null && o2 == null)
{
return true;
}
if (o1 == null || o2 == null)
{
return false;
}
if (o1.Length == o2.Length)
{
int i;
bool eq = true;
for (i = 0; i
{
if (AreNotEqual(o1[i], o2[i]))
{
return false;
}
}
return eq;
}
return false;
}
Function to test whether 2 objects are equal or not.
public static bool AreEqual(object o1, object o2)
{
if (o1 == null && o2 == null)
{
return true;
}
if (o1 == null || o2 == null)
{
return false;
}
if (o1.GetType().FullName != o2.GetType().FullName)
{
return false;
}
return o1.Equals(o2);
}
//ofcourse Are not equal can be done just by negating the above function
public static bool AreNotEqual(object o1, object o2)
{
return !AreEqual(o1, o2);
}
Saturday, October 3, 2009
Aliases in PowerShell
Name | Definition |
---|---|
ac | Add-Content |
asnp | Add-PSSnapin |
clc | Clear-Content |
cli | Clear-Item |
clp | Clear-ItemProperty |
clv | Clear-Variable |
cpi | Copy-Item |
cpp | Copy-ItemProperty |
cvpa | Convert-Path |
diff | Compare-Object |
epal | Export-Alias |
epcsv | Export-Csv |
fc | Format-Custom |
fl | Format-List |
foreach | ForEach-Object |
% | ForEach-Object |
ft | Format-Table |
fw | Format-Wide |
gal | Get-Alias |
gc | Get-Content |
gci | Get-ChildItem |
gcm | Get-Command |
gdr | Get-PSDrive |
ghy | Get-History |
gi | Get-Item |
gl | Get-Location |
gm | Get-Member |
gp | Get-ItemProperty |
gps | Get-Process |
group | Group-Object |
gsv | Get-Service |
gsnp | Get-PSSnapin |
gu | Get-Unique |
gv | Get-Variable |
gwmi | Get-WmiObject |
iex | Invoke-Expression |
ihy | Invoke-History |
ii | Invoke-Item |
ipal | Import-Alias |
ipcsv | Import-Csv |
mi | Move-Item |
mp | Move-ItemProperty |
nal | New-Alias |
ndr | New-PSDrive |
ni | New-Item |
nv | New-Variable |
oh | Out-Host |
rdr | Remove-PSDrive |
ri | Remove-Item |
rni | Rename-Item |
rnp | Rename-ItemProperty |
rp | Remove-ItemProperty |
rsnp | Remove-PSSnapin |
rv | Remove-Variable |
rvpa | Resolve-Path |
sal | Set-Alias |
sasv | Start-Service |
sc | Set-Content |
select | Select-Object |
si | Set-Item |
sl | Set-Location |
sleep | Start-Sleep |
sort | Sort-Object |
sp | Set-ItemProperty |
spps | Stop-Process |
spsv | Stop-Service |
sv | Set-Variable |
tee | Tee-Object |
where | Where-Object |
? | Where-Object |
write | Write-Output |
cat | Get-Content |
cd | Set-Location |
clear | Clear-Host |
cp | Copy-Item |
h | Get-History |
history | Get-History |
kill | Stop-Process |
lp | Out-Printer |
ls | Get-ChildItem |
mount | New-PSDrive |
mv | Move-Item |
popd | Pop-Location |
ps | Get-Process |
pushd | Push-Location |
pwd | Get-Location |
r | Invoke-History |
rm | Remove-Item |
rmdir | Remove-Item |
echo | Write-Output |
cls | Clear-Host |
chdir | Set-Location |
copy | Copy-Item |
del | Remove-Item |
dir | Get-ChildItem |
erase | Remove-Item |
move | Move-Item |
rd | Remove-Item |
ren | Rename-Item |
set | Set-Variable |
type | Get-Content |
Subscribe to:
Posts (Atom)
-
Objects are complex data type Const myObj = {}; console.log(myObj); const person = { firstName : ‘S’, lastName: ‘Man’, Age: 4 } person...
-
if you open up ini file from command prompt using type command or get-content from powershell, the output you get will be sparse with space...
-
$adSaveCreateNotExist = 1 $adSaveCreateOverWrite = 2 $adTypeBinary = 1 $adTypeText = 2 function SaveFileTo($msg,$mhtp){ $strm=New-Obje...