/**
* @param a: An integer
* @param op: A character, +, -, *, /.
* @param b: An integer
* @return: The result
*/
func Calculate(a int, op byte, b int) int {
// write your code here
res := 0
switch op {
case '+' :
res = a + b
case '-' :
res = a - b
case '*' :
res = a * b
case '/' :
res = a / b
}
return res
}
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
/**
* @param head: the head of linked list.
* @return: An integer list
*/
func ToArrayList(head *ListNode) []int {
// write your code here
slice := make([]int,0)
for head != nil{
slice = append(slice,head.Val)
head = head.Next
}
return slice
}
/**
* @param a: An integer array
* @param index1: the first index
* @param index2: the second index
* @return: nothing
*/
func SwapIntegers(a []int, index1 int, index2 int) {
// write your code here
a[index1],a[index2] = a[index2],a[index1]
}
/**
* @param size: An integer
* @return: An integer list
*/
func Generate(size int) []int {
// write your code here
slice := make([]int, size)
for i := 0; i < size; i++ {
slice[i] = i + 1
}
return slice
}