Charora's website  
Home arrow Fun Stuff arrow Dohe (Kabir, Rahim, Tuslidas)
Wednesday, 08 September 2010
 
 
Dohe (Kabir, Rahim, Tuslidas)
Quick Sort using Javascript PDF Print E-mail
Written by Administrator   
Thursday, 31 August 2006

public void swap(int[] a, int i, int j) {
int tmp=a[i];a[i]=a[j];a[j]=tmp;
}

public int partition(int[] a, int low, int high) {
int pivot, p_pos, tmp, i, j;
p_pos = low;
pivot = a[p_pos];
for (i=low+1;i<=high;i++) {
if (a[i] < pivot) {
p_pos++;
swap(a, p_pos, i);
}
}
swap(a, low, p_pos);
return p_pos;
}

public void quicksort(int[] a, int low, int high) {
int pivot;
if (low < high) {
pivot = partition(a, low, high);
quicksort(a, low, pivot-1);
quicksort(a, pivot+1, high);
}
}


Write Comment
Last Updated ( Thursday, 07 September 2006 )
 
Quick Sort using VBScript PDF Print E-mail
Written by Sushma Charora   
Thursday, 31 August 2006

Sub QuickSort(vec,loBound,hiBound)
Dim pivot, pivot1, pivot2, loSwap, hiSwap, temp
if hiBound - loBound = 1 then
if vec(loBound, 0) > vec(hiBound, 0) then
temp=vec(loBound, 0)
vec(loBound, 0) = vec(hiBound, 0)
vec(hiBound, 0) = temp

temp=vec(loBound, 1)
vec(loBound, 1) = vec(hiBound, 1)
vec(hiBound, 1) = temp

temp=vec(loBound, 2)
vec(loBound, 2) = vec(hiBound, 2)
vec(hiBound, 2) = temp
End If
End If

pivot = vec(int((loBound + hiBound) / 2), 0)
vec(int((loBound + hiBound) / 2), 0) = vec(loBound, 0)
vec(loBound, 0) = pivot

pivot1 = vec(int((loBound + hiBound) / 2), 1)
vec(int((loBound + hiBound) / 2), 1) = vec(loBound, 1)
vec(loBound, 0) = pivot1

pivot2 = vec(int((loBound + hiBound) / 2), 2)
vec(int((loBound + hiBound) / 2), 2) = vec(loBound, 2)
vec(loBound, 2) = pivot2

loSwap = loBound + 1
hiSwap = hiBound

do

while loSwap < hiSwap and vec(loSwap, 0) <= pivot
loSwap = loSwap + 1
wend

while vec(hiSwap, 0) > pivot
hiSwap = hiSwap - 1
wend

if loSwap < hiSwap then
temp = vec(loSwap, 0)
vec(loSwap, 0) = vec(hiSwap, 0)
vec(hiSwap, 0) = temp

temp = vec(loSwap, 1)
vec(loSwap, 1) = vec(hiSwap, 1)
vec(hiSwap, 1) = temp

temp = vec(loSwap, 2)
vec(loSwap, 2) = vec(hiSwap, 2)
vec(hiSwap, 2) = temp
End If
loop while loSwap < hiSwap

vec(loBound,0) = vec(hiSwap,0)
vec(hiSwap,0) = pivot

vec(loBound,1) = vec(hiSwap,1)
vec(hiSwap,1) = pivot1
vec(loBound,2) = vec(hiSwap,2)
vec(hiSwap,2) = pivot2

if loBound < (hiSwap - 1) then Call QuickSort(vec,loBound,hiSwap-1)
if hiSwap + 1 < hibound then Call QuickSort(vec,hiSwap+1,hiBound)

End Sub

Sub PrintArray(vec,lo,hi)
Dim i
For i = lo to hi
WScript.echo vec(i,0), vec(i,1), vec(i,2)
Next
End Sub 'PrintArray

Randomize

Dim x(9,3)

For z = 0 to 9
x(z,0) = int(rnd*100)
x(z,1) = 0
x(z,2) = 1
Next
WScript.echo "Jumbled"
Call PrintArray(x,0,9)
Call QuickSort(x,0,9)
WScript.echo "Sorted"
Call PrintArray(x,0,9)


Write Comment
Last Updated ( Thursday, 07 September 2006 )
 
Binary Search Algorithm using VBScript PDF Print E-mail
Written by Sushma Charora   
Wednesday, 30 August 2006
Binary Search Algorithm implemented in VBScript. Copy this script and use it for a multi-dimensional array.

Function BinarySearch(searchItem, startPos, endPos, TheArray, column_to_be_searched)
Dim midPoint
If startPos = endPos Then
If searchItem = TheArray(startPos, column_to_be_searched) Then
BinarySearch = startPos
Else
BinarySearch = -1 '-(startPos) Where it would have been...
End If
ElseIf startPos > endPos Then
BinarySearch = -1 '-(startPos)
Else
midPoint = CLng(startPos + ((endPos - startPos) / 2))
If searchItem = TheArray(midPoint, column_to_be_searched) Then
BinarySearch = midPoint
Else
If searchItem < TheArray(midPoint, column_to_be_searched) Then
BinarySearch = BinarySearch(searchItem, startPos, midPoint - 1, TheArray, column_to_be_searched)
Else
BinarySearch = BinarySearch(searchItem, midPoint + 1, endPos, TheArray, column_to_be_searched)
End If
End If
End If
End Function 'BinarySearch


Write Comment
Last Updated ( Tuesday, 06 November 2007 )
 
FTP Script to upload files to a web-site PDF Print E-mail
Written by Sushma Charora   
Wednesday, 30 August 2006
If you want to upload certain files on your website frequently, this script can help you.

1. Create a folder "c:\upload\"
2. Copy file1.htm, file2.htm etc to "c:\upload\"
3. Copy this script and paste into notepad
4. Make Necessary Changes
    Specify username and password in Line 9
    Specify remote folder name in Line 11
    Change www.charora.com to your domain name in Line 24
5. SaveAs "upload.bat"
6. Run upload.bat

@echo off
rem Author: Sushma Charora
rem Date: 8/30/2006 11:30 AM PST
rem This script FTP over files to
rem the web-site automatically.
rem If you have any question contact me at
rem first we build a response file containing the FTP commands
ECHO verbose off > c:\upload\ftp.in
ECHO user username password >> c:\upload\ftp.in
ECHO bin >> c:\upload\ftp.in
ECHO cd /remotefolder >> c:\upload\ftp.in
ECHO put c:\upload\file1.htm >> c:\upload\ftp.in
ECHO put c:\upload\file2.htm >> c:\upload\ftp.in
ECHO put c:\upload\file3.htm >> c:\upload\ftp.in
ECHO put c:\upload\file4.htm >> c:\upload\ftp.in
ECHO put c:\upload\file5.htm >> c:\upload\ftp.in
ECHO put c:\upload\file6.htm >> c:\upload\ftp.in
ECHO put c:\upload\file7.htm >> c:\upload\ftp.in
ECHO quit >> c:\upload\ftp.in
rem ok, now we have created the file we want to be executed by ftp
rem start ftp
rem -n means suppress autologin
rem -s:c:\upload\ftp.in means take commands from that file
ftp -n -s:c:\upload\ftp.in www.charora.com
del c:\upload\ftp.in
rem Done!
GOTO QUIT
:QUIT
Echo that's it!


Write Comment
Last Updated ( Tuesday, 06 November 2007 )
 
Script to generate list of registered extensions PDF Print E-mail
Written by Sushma Charora   
Tuesday, 29 August 2006
Script to generate list of all registered extensions on your machine into an excel file. Please email me at , if you have any question about the script.

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006

Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7

Dim WriteToFile

Dim Create
Dim FSO ' FileSystemObject
Dim TS ' TextStreamObject
Create = True
WriteToFile = "C:\Temp\Ext.xls"
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(WriteToFile) Then
FSO.DeleteFile WriteToFile, true
End If
Set TS = FSO.CreateTextFile(WriteToFile, Create)

strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = ""

oReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys
TS.Write "Extension" & char(9) & "Value Name 1" & char(9) & "Date Type 1" & char(9) & "Date Value 1" & char(9) & "Value Name 2" & char(9) & "Date Type 2" & char(9) & "Date Value 2" & char(9) & "Value Name 3" & char(9) & "Date Type 3" & char(9) & "Date Value 3" & char(9) & "Value Name 4" & char(9) & "Date Type 4" & char(9) & "Date Value 4" & char(9) & "Value Name 5" & char(9) & "Date Type 5" & char(9) & "Date Value 5" & char(9) & "Value Name 6" & char(9) & "Date Type 6" & char(9) & "Date Value 6" & char(13) & char(10)
For Each subkey In arrSubKeys
if left(subkey, 1) = "." then
TS.Write subkey
oReg.EnumValues HKEY_CLASSES_ROOT, subkey, arrValueNames, arrValueTypes
if IsArray(arrValueNames) then
For i=0 To UBound(arrValueNames)
TS.Write char(9) & arrValueNames(i)
Select Case arrValueTypes(i)
Case REG_SZ
TS.Write char(9) & "String"
oReg.GetStringValue HKEY_CLASSES_ROOT, subkey, arrValueNames(i), strValue
TS.Write char(9) & strValue
Case REG_EXPAND_SZ
TS.Write char(9) & "Expanded String"
oReg.GetExpandedStringValue HKEY_CLASSES_ROOT, subkey, arrValueNames(i), strValue
TS.Write char(9) & strValue
Case REG_BINARY
TS.Write char(9) & "Binary"
oReg.GetBinaryValue HKEY_CLASSES_ROOT, subkey, arrValueNames(i), strValue
TS.Write char(9) & strValue
Case REG_DWORD
TS.Write char(9) & "DWORD"
oReg.GetDWORDValue HKEY_CLASSES_ROOT, subkey, arrValueNames(i), strValue
TS.Write char(9) & strValue
Case REG_MULTI_SZ
TS.Write char(9) & "Multi String"
oReg.GetMultiStringValue HKEY_CLASSES_ROOT, subkey, arrValueNames(i), strValue
TS.Write char(9) & strValue
End Select
Next
else
TS.Write char(9) & arrValueNames
Select Case arrValueTypes
Case REG_SZ
TS.Write char(9) & "String"
oReg.GetStringValue HKEY_CLASSES_ROOT, subkey, arrValueNames, strValue
TS.Write char(9) & strValue
Case REG_EXPAND_SZ
TS.Write char(9) & "Expanded String"
oReg.GetExpandedStringValue HKEY_CLASSES_ROOT, subkey, arrValueNames, strValue
TS.Write char(9) & strValue
Case REG_BINARY
TS.Write char(9) & "Binary"
oReg.GetBinaryValue HKEY_CLASSES_ROOT, subkey, arrValueNames, strValue
TS.Write char(9) & strValue
Case REG_DWORD
TS.Write char(9) & "DWORD"
oReg.GetDWORDValue HKEY_CLASSES_ROOT, subkey, arrValueNames, strValue
TS.Write char(9) & strValue
Case REG_MULTI_SZ
TS.Write char(9) & "Multi String"
oReg.GetMultiStringValue HKEY_CLASSES_ROOT, subkey, arrValueNames, strValue
TS.Write char(9) & strValue
End Select
end if
TS.Write char(13)
end if
next
TS.Close
Set FSO = Nothing
Set TS = Nothing


Write Comment
Last Updated ( Tuesday, 06 November 2007 )
 
Google
 
Top! Top!