GOLANG_INTERVIEW Telegram 313
👣 Сколько времени в минутах займет у вас написание процедуры обращения односвязного списка?

package main

import "fmt"

type Node struct {
Val int
Next *Node
}

func reverseLinkedList(head *Node) *Node {
var prev *Node
curr := head
for curr != nil {
Next := curr.Next
curr.Next = prev
prev = curr
curr = Next
}
return prev
}

// можно сократить curr
// func reverseLinkedList(head *Node) *Node {
// var prev *Node
// for head != nil {
// Next := head.Next
// head.Next = prev
// prev = head
// head = Next
// }
// return prev
// }

// можно сократить Next (через множественное присваивание)
// func reverseLinkedList(head *Node) *Node {
// var prev *Node
// for head != nil {
// head.Next, prev, head = prev, head, head.Next
// }
// return prev
// }

// или создавая новые узлы
// func reverseLinkedList(head *Node) *Node {
// var result *Node
// curr := head
// for curr != nil {
// result = &Node{curr.Val, result}
// curr = curr.Next
// }
// return result
// }

func printLinkedList(head *Node) {
current := head
for current != nil {
fmt.Printf("%d -> ", current.Val)
current = current.Next
}
fmt.Println("nil")
}

func main() {
node1 := &Node{Val: 1}
node2 := &Node{Val: 2}
node3 := &Node{Val: 3}
node4 := &Node{Val: 4}
node5 := &Node{Val: 5}
node1.Next = node2
node2.Next = node3
node3.Next = node4
node4.Next = node5
fmt.Println("Исходный список:")
printLinkedList(node1)
reversedHead := reverseLinkedList(node1)
fmt.Println("Обращенный список:")
printLinkedList(reversedHead)
}


Пишите свое решение в комментариях👇

@golang_interview
Please open Telegram to view this post
VIEW IN TELEGRAM
👍111🔥1



tgoop.com/golang_interview/313
Create:
Last Update:

👣 Сколько времени в минутах займет у вас написание процедуры обращения односвязного списка?

package main

import "fmt"

type Node struct {
Val int
Next *Node
}

func reverseLinkedList(head *Node) *Node {
var prev *Node
curr := head
for curr != nil {
Next := curr.Next
curr.Next = prev
prev = curr
curr = Next
}
return prev
}

// можно сократить curr
// func reverseLinkedList(head *Node) *Node {
// var prev *Node
// for head != nil {
// Next := head.Next
// head.Next = prev
// prev = head
// head = Next
// }
// return prev
// }

// можно сократить Next (через множественное присваивание)
// func reverseLinkedList(head *Node) *Node {
// var prev *Node
// for head != nil {
// head.Next, prev, head = prev, head, head.Next
// }
// return prev
// }

// или создавая новые узлы
// func reverseLinkedList(head *Node) *Node {
// var result *Node
// curr := head
// for curr != nil {
// result = &Node{curr.Val, result}
// curr = curr.Next
// }
// return result
// }

func printLinkedList(head *Node) {
current := head
for current != nil {
fmt.Printf("%d -> ", current.Val)
current = current.Next
}
fmt.Println("nil")
}

func main() {
node1 := &Node{Val: 1}
node2 := &Node{Val: 2}
node3 := &Node{Val: 3}
node4 := &Node{Val: 4}
node5 := &Node{Val: 5}
node1.Next = node2
node2.Next = node3
node3.Next = node4
node4.Next = node5
fmt.Println("Исходный список:")
printLinkedList(node1)
reversedHead := reverseLinkedList(node1)
fmt.Println("Обращенный список:")
printLinkedList(reversedHead)
}


Пишите свое решение в комментариях👇

@golang_interview

BY Golang вопросы собеседований




Share with your friend now:
tgoop.com/golang_interview/313

View MORE
Open in Telegram


Telegram News

Date: |

In 2018, Telegram’s audience reached 200 million people, with 500,000 new users joining the messenger every day. It was launched for iOS on 14 August 2013 and Android on 20 October 2013. In the next window, choose the type of your channel. If you want your channel to be public, you need to develop a link for it. In the screenshot below, it’s ”/catmarketing.” If your selected link is unavailable, you’ll need to suggest another option. Commenting about the court's concerns about the spread of false information related to the elections, Minister Fachin noted Brazil is "facing circumstances that could put Brazil's democracy at risk." During the meeting, the information technology secretary at the TSE, Julio Valente, put forward a list of requests the court believes will disinformation. It’s yet another bloodbath on Satoshi Street. As of press time, Bitcoin (BTC) and the broader cryptocurrency market have corrected another 10 percent amid a massive sell-off. Ethereum (EHT) is down a staggering 15 percent moving close to $1,000, down more than 42 percent on the weekly chart. When choosing the right name for your Telegram channel, use the language of your target audience. The name must sum up the essence of your channel in 1-3 words. If you’re planning to expand your Telegram audience, it makes sense to incorporate keywords into your name.
from us


Telegram Golang вопросы собеседований
FROM American