We need to do coding for queue implementation, we did as
package main
import "fmt"
type queue struct {
items []int
}
func (q *queue) insertion(item int) {
q.items = append(q.items, item)
}
func (q *queue) deletion() {
if len(q.items) == 0 {
fmt.Println("Out of Bounds")
}
items := q.items[1:]
q.items = items
}
func main() {
var n int
_, err := fmt.Scanln(&n)
if err != nil || n < 0 {
return
}
q := queue{}
q.insertion(n)
q.deletion(n)
}
Not sure where we went wrong
NobbZ
(Norbert Melzer)
February 23, 2021, 6:06am
2
You read a single number from stdin
, add it to the queue and then you are calling deletion()
with one argument but only have defined deletion()
without arguments.
Please also do not just throw some exercise and code at us, but tell us what your problem with your current code is. Do you get an error on compilation? Is the output not as expected? Etc…
NobbZ
(Norbert Melzer)
February 23, 2021, 6:28am
4
Yes, and I told you why. You are calling deletion(n)
but there is no deletion
function that would take any arguments.
NobbZ
(Norbert Melzer)
February 23, 2021, 7:35am
7
You are reading in the slice of data, and then insert the number of items at the end.
NobbZ
(Norbert Melzer)
February 23, 2021, 7:55am
9
Re read instructions. How many items are you supposed to drop, and how many do you actually drop?
NobbZ
(Norbert Melzer)
February 23, 2021, 8:22am
12
Carefully check the error and also check your failure conditions in the deletion method.
NobbZ
(Norbert Melzer)
February 23, 2021, 8:37am
14
You are trying to drop 3 items from a slice of length 2, you can’t do that. Check if your slice is long enough before dropping.