Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Data Structures and Program Design Using Python

You're reading from   Data Structures and Program Design Using Python A Self-Teaching Introduction to Data Structures and Python

Arrow left icon
Product type Paperback
Published in Aug 2024
Publisher Mercury_Learning
ISBN-13 9781836640738
Length 394 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (3):
Arrow left icon
Mercury Learning and Information Mercury Learning and Information
Author Profile Icon Mercury Learning and Information
Mercury Learning and Information
D. Malhotra D. Malhotra
Author Profile Icon D. Malhotra
D. Malhotra
N. Malhotra N. Malhotra
Author Profile Icon N. Malhotra
N. Malhotra
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface
1. Acknowledgments
2. Chapter 1: Introduction to Data Structures FREE CHAPTER 3. Chapter 2: Introduction to Python 4. Chapter 3: Arrays/Lists 5. Chapter 4: Linked Lists 6. Chapter 5: Queues 7. Chapter 6: Searching and Sorting 8. Chapter 7: Stacks 9. Chapter 8: Trees 10. Chapter 9: Multi-Way Search Trees 11. Chapter 10: Hashing 12. Chapter 11: Files 13. Chapter 12: Graphs 14. Index
Appendix: Answers to Multiple Choice Questions

7.5IMPLEMENTATION OF A STACK

Stacks can be represented by two data structures:

1.using arrays

2.using a linked list

7.5.1Implementation of Stacks Using Arrays

Stacks can be easily implemented using arrays. Initially, the TOP of the stack points at the first position or location of the array. As we insert new elements into the stack, the TOP keeps on incrementing, always pointing to the position where the next element will be inserted. The representation of a stack using an array is shown as follows:

image

FIGURE 7.6 Array representation of a stack

7.5.2Implementation of Stacks Using Linked Lists

We studied how a stack is implemented using an array. Now let us discuss the same using linked lists. We already know that in linked lists, dynamic memory allocation takes place; that is, the memory is allocated at runtime. But in the case of arrays, memory is allocated at the start of the program. If we are aware of the maximum size of the stack in advance, then the implementation of stacks...

lock icon The rest of the chapter is locked
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Data Structures and Program Design Using Python
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon