Skip to content

Commit e9dcc75

Browse files
committed
BubbleSort and create file
Added BubbleSort Algorithms in vb and python and algorithm to create a text file on vb
1 parent 2c4e5c9 commit e9dcc75

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

Create File/CreateFile.vb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Imports System.IO
2+
Imports System.Text
3+
4+
Module Module1
5+
6+
Sub Main()
7+
Dim path As String = "c:\temp\MyTest.txt"
8+
9+
' Creates (or overwrites) the file in the directory "c:\temp\MyTest.txt".
10+
Dim fs As FileStream = File.Create(path)
11+
12+
' Add text to the file.
13+
Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is some text in the file.")
14+
fs.Write(info, 0, info.Length)
15+
fs.Close()
16+
End Sub
17+
18+
End Module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def BubbleSort(lst):
2+
lst = list(lst) #copy collection to list
3+
for passesLeft in range(len(lst)-1, 0, -1):
4+
for i in range(passesLeft):
5+
if lst[i] < lst[i + 1]:
6+
lst[i], lst[i + 1] = lst[i + 1], lst[i]
7+
return lst
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Module Module1
2+
Sub Bubblesort(Array() as Integer, Length as Integer)
3+
Dim I As Integer
4+
Dim J As Integer
5+
Dim Temp As Integer
6+
Dim Length As Integer
7+
Dim Array() As String = {}
8+
9+
For I = Length - 1 To 1 Step -1 'the last element on the array does not get sorted.
10+
For J = 0 To I - 1
11+
If Array(J) > Array(J + 1) Then ' Compare neighboring elements
12+
Temp = Array(J)
13+
Array(J) = Array(J + 1)
14+
Array(J + 1) = Temp
15+
16+
End If
17+
Next
18+
Next
19+
End Sub
20+
End Module

0 commit comments

Comments
 (0)