We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
代码如下
package main import "fmt" func main() { for { var n int _, err := fmt.Scan(&n) if err != nil { return } if n == 0 { fmt.Println("list is empty") continue } var head *Node dummyNode := &Node{next: head} temp := dummyNode for n > 0 { var num int _, err = fmt.Scan(&num) if err != nil { return } newNode := &Node{val: num} temp.next = newNode temp = temp.next n-- } head = dummyNode.next show(head) show(head.reverse()) } } func show(head *Node) { if head == nil { return } cur := head for cur != nil { fmt.Printf("%d ", cur.val) cur = cur.next } fmt.Println() } type Node struct { val int next *Node } func (l *Node) reverse() *Node { if l == nil || l.next == nil { return l } var pre *Node cur := l for cur != nil { temp := cur.next cur.next = pre pre = cur cur = temp } return pre }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
代码如下
The text was updated successfully, but these errors were encountered: