mirror of
https://codeberg.org/scip/rpnc.git
synced 2025-12-17 04:21:01 +01:00
added swap stack command, bump version (#2)
This commit is contained in:
20
stack.go
20
stack.go
@@ -115,6 +115,26 @@ func (s *Stack) Shift(num ...int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Stack) Swap() {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
if s.linklist.Len() < 2 {
|
||||
return
|
||||
}
|
||||
|
||||
a := s.linklist.Back()
|
||||
s.linklist.Remove(a)
|
||||
|
||||
b := s.linklist.Back()
|
||||
s.linklist.Remove(b)
|
||||
|
||||
s.Debug(fmt.Sprintf("swapping %.2f with %.2f", b.Value, a.Value))
|
||||
|
||||
s.linklist.PushBack(a.Value)
|
||||
s.linklist.PushBack(b.Value)
|
||||
}
|
||||
|
||||
// Return the last num items from the stack w/o modifying it.
|
||||
func (s *Stack) Last(num ...int) []float64 {
|
||||
items := []float64{}
|
||||
|
||||
Reference in New Issue
Block a user