Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a node struct with an integer value field named 'data'.
DSA Go
type Node struct {
[1] int
next *Node
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'val' instead of 'data' as the field name.
Naming the field with uppercase which changes visibility.
✗ Incorrect
The field name for the integer value in the node struct is 'data'.
2fill in blank
mediumComplete the code to create a pointer to the next node named 'next'.
DSA Go
type Node struct {
data int
[1] *Node
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which usually points to the previous node.
Using generic names like 'pointer' or 'link' which are less clear.
✗ Incorrect
The pointer to the next node is conventionally named 'next'.
3fill in blank
hardFix the error in the code to correctly initialize a new node with value 10.
DSA Go
newNode := &Node[1]data: 10
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses '()' which is invalid for struct literals.
Using square brackets '[]' or angle brackets '<>' which are incorrect.
✗ Incorrect
Struct literals in Go use curly braces '{}' without parentheses.
4fill in blank
hardFill both blanks to define a function that returns the next node pointer.
DSA Go
func (n *Node) [1]() *Node { return n.[2] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase method name 'next' which is unexported.
Using incorrect field names like 'NextNode' or 'nextNode'.
✗ Incorrect
The method name should be 'Next' (exported) and it returns the 'next' pointer field.
5fill in blank
hardFill all three blanks to create a function that sets the next node pointer.
DSA Go
func (n *Node) [1]([2] *Node) { n.[3] = [2] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameter name same as field name causing confusion.
Using lowercase method name or wrong field names.
✗ Incorrect
The method name is 'SetNext', parameter name 'node', and field name 'next'.
