Linked list vs. dynamic array for implementing a stack

后端 未结 5 1086
再見小時候
再見小時候 2020-12-24 13:02

I\'ve started reviewing data structures and algorithms before my final year of school starts to make sure I\'m on top of everything. One review problem said \"Implement a s

5条回答
  •  时光说笑
    2020-12-24 13:46

    Resizing the dynamic array would not be an expensive task if you design your implementation well.

    For instance, to grow the array, if it is full, create a new array of twice the size, and copy items.

    You will end up with an amortized cost of ~3N for adding N items.

提交回复
热议问题