This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main(){ | |
fmt.Println("Bubble Sort:") | |
fmt.Println(bubbleSort([]int{5,2,3,22,-4,0,11,-5,1,1})) | |
fmt.Println(bubbleSort([]int{-5,12,3,2,-4,0,11,-5,1,1})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main(){ | |
fmt.Println("Merge Sort:") | |
fmt.Println(mergeSort([]int{2,1,-3,0})) | |
fmt.Println(mergeSort([]int{22,1111,-113,10,6})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main(){ | |
fmt.Printf("Inerstion sort: %d", insertionSort([]int{2,3,-1,-4,9,1,2,0})) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main(){ | |
fmt.Println("Is the the string the same if we reverse it ?") | |
fmt.Println(isPalindromic("AHA")) | |
fmt.Println(isPalindromic("Go")) | |
} | |
func isPalindromic(s string)bool{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func deleteDuplicatesSortedArray(arr []int)[]int{ | |
for i:= 0 ; i < len(arr) - 1 ; i++ { | |
if arr[i] == arr[i+1]{ | |
arr = append(arr[:i], arr[i+1:]...) | |
} | |
} | |
return arr | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func evenOdd(nums []int){ | |
for i, j := 0 , len(nums) - 1 ; i <= j;{ | |
if(nums[i] % 2 != 0 && nums[j] % 2 == 0){ // Even | |
nums[i], nums[j] = nums[j],nums[i] | |
} | |
if nums[i] % 2 == 0 { | |
i++ | |
} | |
if nums[j] % 2 != 0 { | |
j-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func dutchFlagPartition(arr []int, pivotIndex int) []int{ | |
pivot := arr[pivotIndex] | |
for i:= 0 ; i < len(arr) ; i++ { | |
for j:= i + 1 ; j < len(arr) ; j++ { | |
if arr[j] < pivot { | |
arr[i], arr[j] = arr[j], arr[i] | |
break; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func improvedDutchFlag(arr []int, pivotIndex int)[]int{ | |
pivot := arr[pivotIndex] | |
smaller := 0; | |
for i:=0; i < len(arr) ; i++ { | |
if arr[i] < pivot { | |
arr[i], arr[smaller] = arr[smaller] , arr[i] | |
smaller++ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main (){ | |
var l = LinkedList{} | |
var p Person= Person{"Abdulrahman",3} | |
l.insert(&p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type node struct { | |
data int | |
next *node | |
} | |
type queue struct { |