1. Trang chủ
  2. » Công Nghệ Thông Tin

Đề Thi Cơ Sở Dữ Liệu

21 516 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 21
Dung lượng 456,98 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Stack ADT Abstract Data Type... Stack Implementation in C• What is .h file?... Stack Implementation in C#define maxsize=5;... Stack Implementation in CInit... Stack Implementation in CPu

Trang 1

by Le Quy Loc Information Technology Faculty

DUT

Trang 3

Stack ADT (Abstract Data Type)

Trang 4

Stack

Trang 5

Design Stack

Trang 6

Push An Element Into a Stack

• Algorithm

1 If stack is still empty

1.1 Save the element to the top of stack 1.2 Increase the number of elements by 1

top

1 5

7

top =2 top=3

Trang 7

Stack Implementation in C

• What is h file?

Trang 8

Stack Implementation in C

#define maxsize=5;

Trang 9

Stack

Implementation

in C

Trang 10

Stack Implementation in C

Init

Trang 11

Stack Implementation in C

Push

Trang 12

Stack Implementation in C

Pop

Trang 13

Stack Implementation in C

Empty

Trang 14

Exercises

Trang 15

Determine the values of stack and top after each commands and what are printed in the program?

1 int top, element;

2 intstack[10];

3 int x, y, z;

4 x = 0;

5 y = 5;

6 z = y / 2;

7 init(&top); 8 push(stack, &top, x);

9 push(stack, &top, y);

10 z = pop(stack, &top);

11 push(stack, &top, x+1); 12 push(stack, &top, y);

13 push(stack, &top, 3);

14 while (!empty(&top))

15 {

16 z = pop(stack, &top); 17 printf(“%d ”, z);

18 }

19 printf("x = %d",x);

20 printf(“y = %d”,y);

21 printf("z = %d",z);

Trang 16

Using the stack operations, write functions to

1 Copy data from a stack to another stack

2 Sum of negative elements

3 Delete all elements equal x in a stack

4 Convert decimal to binary

Trang 17

Homework

Trang 18

Convert infix expression to postfix

expression

• Write a function to calculate

– (3 + 4)*5

– 3 + (4 - 2 + (12 – 6)/2)*6 + 8 * 3^2

Trang 19

Convert infix expression to postfix

expression

• Infix expression: operators between operands

– Good: easy to read for human

– Bad: difficult for computer to calculate

Trang 20

Convert infix expression to postfix

Trang 21

Convert infix expression to postfix

Ngày đăng: 29/09/2016, 08:47

TỪ KHÓA LIÊN QUAN

w