- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1082 Articles for Go Programming
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
183 Views
ExampleAbs(x, y) => √(x)2+(y)2Scale(f) => (x*f, y*f)ApproachDefine a vertex as a struct.Initialize the vertex with some x and value.Define a method to calculate absolute(x, y).Define a method to calculate scale(x*f, y*f).Example Live Demopackage main import ( "fmt" "math" ) type Vertex struct { X, Y float64 } func Abs(v Vertex) float64{ return math.Sqrt(v.X*v.X + v.Y*v.Y) } func Scale(v *Vertex, f float64) { v.X = v.X * f v.Y = v.Y * f } func main() { v := Vertex{3, 4} fmt.Println("Given vertex is: ", v) fmt.Println("Absolute value of given vertex is: ", ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
164 Views
ExampleApproachAsk the user to enter the size of array.Make a string array of given size.Ask the user to enter elements.At the end, print the array.Example Live Demopackage main import "fmt" func main(){ arr := []int{10, 20, 30, 60, 40, 50} boolArr := []bool{true, false, true, false, true, false} fmt.Println("Input Array is: ", arr) fmt.Println("Input Boolean Array is: ", boolArr) visitedArray := []struct{ i int b bool }{ {10, true}, {20, false}, {30, true}, {60, false}, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
789 Views
ExampleApproachAsk the user to enter the size of array.Make a string array of given size.Ask the user to enter the elements.At the end, print the array.Example Live Demopackage main import ( "fmt" ) func main(){ fmt.Printf("Enter size of your array: ") var size int fmt.Scanln(&size) var arr = make([]string, size) for i:=0; i
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
ExampleApproachAsk the user to enter the size of array.Make an integer array of given size.Ask the user to enter elements.At the end, print the array.Example Live Demopackage main import ( "fmt" ) func main(){ fmt.Printf("Enter size of your array: ") var size int fmt.Scanln(&size) var arr = make([]int, size) for i:=0; i
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
97 Views
ExamplesApproachStep 1 − Define a method that accepts the head of a doubly linked list.Step 2 − Initialize temp:=head, count:=0Step 3 − Iterate temp until it becomes nil.Step 4 − Increase count by 1.Step 5 − At the end, print count.Example Live Demopackage main import "fmt" type Node struct { prev *Node value int next *Node } func CreateNewNode(value int) *Node{ var node Node node.next = nil node.value = value node.prev = nil return &node } func TraverseDoublyLL(head * Node){ // Forward Traversal fmt.Printf("Doubly Linked List: ") count := 0 ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
367 Views
A doubly linked list node contains three items, where two items point to the next and previous nodes, and the third item contains the value of that node.ExampleApproachStep 1 − Define a method that accepts the head of a doubly linked list.Step 2 − Initialize temp:=head.Step 3 − Iterate temp until it becomes nil.Step 4 − Print temp.value.Example Live Demopackage main import "fmt" type Node struct { prev *Node value int next *Node } func CreateNewNode(value int) *Node{ var node Node node.next = nil node.value = value node.prev = nil return &node } ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
94 Views
ExamplesExampleApproach to solve this problem Live Demopackage main import "fmt" type Node struct { value int next *Node } func NewNode(value int, next *Node) *Node{ var n Node n.value = value n.next = next return &n } func TraverseLinkedList(head *Node){ temp := head for temp != nil { fmt.Printf("%d ", temp.value) temp = temp.next } fmt.Println() } func InsertNodeAtIthIndex(head *Node, index, data int) *Node{ if head == nil{ head = NewNode(data, nil) return head } if ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
240 Views
ExampleSuppose we have the following tree.Inorder Tree Traversal Output − 4 2 5 1 6 3 7Approach to solve this problemStep 1 − If the root node of the given tree is nil, then return; else, follow the steps given below.Step 2 − Traverse the Left sub-tree.Step 3 − Print the root node data.Step 4 − Traverse the Right sub-tree.Example Live Demopackage main import "fmt" type Node struct { data int left *Node right *Node } func (root *Node)InOrderTraversal(){ if root !=nil{ root.left.InOrderTraversal() fmt.Printf("%d ", root.data) root.right.InOrderTraversal() ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
67 Views
ExamplesExample Live Demopackage main import "fmt" type Node struct { value int next *Node } func NewNode(value int, next *Node) *Node{ var n Node n.value = value n.next = next return &n } func TraverseLinkedList(head *Node){ temp := head for temp != nil { fmt.Printf("%d ", temp.value) temp = temp.next } fmt.Println() } func InsertNodeAtIthIndex(head *Node, index, data int) *Node{ if head == nil{ head = NewNode(data, nil) return head } if index == 0{ ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
63 Views
ExamplesExample Live Demopackage main import "fmt" type Node struct { value int next *Node } func NewNode(value int, next *Node) *Node{ var n Node n.value = value n.next = next return &n } func TraverseLinkedList(head *Node){ temp := head for temp != nil { fmt.Printf("%d ", temp.value) temp = temp.next } fmt.Println() } func InsertNodeAtIthIndex(head *Node, index, data int) *Node{ if head == nil{ head = NewNode(data, nil) return head } if index == 0{ ... Read More