Save this video free

Lecture 28: A stack data type

Burton Ma · 49:41 · Watch on YouTube

Part of Queen's University CISC220. See all 23 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Burton Ma explains how a stack follows last-in, first-out access and implements it in C with dynamically allocated, singly linked nodes. The lecture builds a stack API around `push`, `pop`, size and emptiness checks, printing, and cleanup, emphasizing pointer updates and safe memory management.

Key takeaways

Chapters

0:00 Stack Behavior and Linked Nodes in C
7:00 Representing the Stack with a Top Pointer
11:12 C Type Aliases and the Stack Header
20:55 Defining Stack and Node Structures
29:19 Creating and Initializing an Empty Stack
32:39 Push Allocates and Links a New Top Node
37:47 Pop Returns the Integer and Frees Its Node
41:36 Freeing and Printing Linked Stack Contents
48:40 Demo Run and the Challenge of Generic Stacks

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:00 your memory on what a stack is. So stack's one of the fundamental data structures. Well, it's one of the fundamental simple data structures in computing science. Um, conceptually a stack models a stack of stuff, right? So here we got a stack of folders, we got a stack of books, we got a stack of pancakes. Um now the difference between real life and computing science uh is that in computing science with a stack traditionally you can only access the top of the stack right so in this stack of books I'm only able to access that top book right whereas in real life if you wanted to you could go into the middle of the stack and pull out the middle book right so a data structure stack you can only access the top element so everything happens at the top of the stack right if

0:49 I wanted to get to the bottom of this book stack of books, I'd have to remove all of the individual books and then get to the bottom book. Right? So, classically stacks only implement uh two operations, right? There's an operation called push. Push adds an element to the top of the stack. Pop removes the top element of the stack and typically it returns the element back to the caller. So, a stack is a linear data structure. It's a linear sequence of uh of stuff. And so you can implement these things in many different ways. So you could use a list if you already had a list. This is C, so we don't have a list. Um, today we're going to use an array to hold the elements of the stack. You should have done that in 124. Um, and then I Oh, sorry. Today we're not using an array.

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Burton Ma.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.