How to use library for stack and queue in golang

package main

import (
"container/list"
"fmt"
)

func main() {

stack := list.New()
//[]

stack.PushBack(2)
//[2]
stack.PushBack(3)
//[3,2]
stack.PushBack(4)
//[4,3,2]
stack.PushBack(5)
//[5,4,3,2]
stack.PushFront(6)
//[5,4,3,2,6]

e := stack.Front()
//-> 6
fmt.Printf("%v", e.Value)

e = stack.Front()
fmt.Printf("%v", e.Value)

v := stack.Remove(stack.Front())
//remove 6
fmt.Printf("%v", v)
v = stack.Remove(stack.Front())
//remove 2
fmt.Printf("%v", v)
v = stack.Remove(stack.Back())
//remove 5
fmt.Printf("%v", v)

stack.Len()


}

Comments

Popular posts from this blog

Fixing the DeepSpeed Import Error While Fine-Tuning the Qwen Model

Amazon Linux 2023 - User data configuration for launch templates to connect to the EKS cluster

How to create ISM policy and rotate logs in opensearch