计算机科学概论(第9版)LectureSlide_08.pptVIP

  • 1
  • 0
  • 约1.27万字
  • 约 53页
  • 2018-02-06 发布于河南
  • 举报
计算机科学概论(第9版)LectureSlide_08

Data Abstraction Basic Data Structures Chapter 8 Abstract Data Type Abstract Data Type as a design tool Concerns only on the important concept or model No concern on implementation details. Stack Queue is an example of ADT An array is not ADT. What is the difference? Stack Queue vs. Array Arrays are data storage structures while stacks and queues are specialized DS and used as programmer’s tools. Stack – a container that allows push and pop Queue - a container that allows enqueue and dequeue No concern on implementation details. In an array any item can be accessed, while in these data structures access is restricted. They are more abstract than arrays. Stack Stacks are Used for handling nested structures: processing directories within directories evaluating expressions within expressions handling branching processes traversing a branching tree structure planning a move in a chess game tracking the sequence of method calls in a Java program Stacks A stack is a data structure that only allows items to be inserted and removed at one end We call this end the top of the stack The other end is called the bottom Access to other items in the stack is not allowed A LIFO (Last In First Out) data structure Using a Stack What Are Stacks Used For? Most programming languages use a “call stack” to implement function calling When a method is called, its line number and other useful information are pushed (inserted) on the call stack When a method ends, it is popped (removed) from the call stack and execution restarts at the indicated line number in the method that is now at the top of the stack The Call Stack Call Stacks and Recursion A call stack is what makes recursion possible Stacks are also important when traversing tree data structures They enable us to “backtrack” through the tree We’ll see more about this later in the course Stack Operations A stack should implement (at least) these operations: push – insert an item at the top of the stack pop – remove and r

文档评论(0)

1亿VIP精品文档

相关文档