From the course: Advanced Go Programming: Data Structures, Code Architecture, and Testing

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Implementing data structures

Implementing data structures

- [Instructor] Even though Go doesn't offer ready-made data structures like other languages do, we have all the building blocks we need to implement any data structure. Let's take a closer look at how you can achieve this. A stack is a data structure that's related to the linked list. It has a last in, first out element access. New elements are added to the top of the stack and the latest element is read first. They're often used by algorithms because the function call stack exhibits the same behavior. Stacks expose two operations. The Push operation adds a new element to the top of the stack while the Pop operation reads and removes the last element from the top of the stack. Go recently introduced support for generic code, making it possible for us to write code that can be used with multiple data types. We can easily implement a stack by using generic code and a slice. This slice can hold the methods which…

Contents