You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

956 B

listpushback

Instructions

Write a function ListAt that haves one pointer to the list, l, and an int as parameters. This function should print a Node of the linked list, depending on the number, nbr.

  • In case of error it should print nil

Expected function and structure

type Node struct {
	Data interface{}
	Next *Node
}


func ListAt(l *Node, nbr int) *Node{

}

Usage

Here is a possible program to test your function :

package main

import (
	"fmt"
	piscine ".."
)

func main() {
	link := &Node{}

	ListPushBack(link, "hello")
	ListPushBack(link, "how are")
	ListPushBack(link, "you")
	ListPushBack(link, 1)

	fmt.Println()

	fmt.Println(ListAt(link, 3).Data)
	fmt.Println(ListAt(link, 1).Data)
	fmt.Println(ListAt(link, 7))
}

And its output :

student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test
you
hello
<nil>
student@ubuntu:~/piscine/test$