Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Latest commit

 

History

History
83 lines (67 loc) · 2.18 KB

File metadata and controls

83 lines (67 loc) · 2.18 KB

Oefeningen 5.6 · Slide 89 - 91

Theorie

Oefening 5.6.1

  data t b i x
1) [null, null, null, null, null] - 1      
2)     true    
3) [-3, null, null, null, null] 0      
4)     false    
5)       -3  
6) [-3, null, null, null, null] -1     -3
7)     true    
8) [38, null, null, null, null] 0      
9) [38, 88, null, null, null] 1      
10) [38, 88, 77, null, null] 2      
11)     false    
12)       77  
13) [38, 88, 77, null, null] 1     77
14)       88  

Oefening 5.6.2

stack t
[null, null, null, null] -1
[100, null, null, null] 0
[100, 54, null, null] 1
[100, 60, null, null] 1
[100, 60, 630, null] 2

54 100 630 630 60

Oefening 5.6.3

full(I: /): vlag: boolean
    * Preconditie: de stapel s bestaat
    * Postconditie: de waarde true of false werd afgeleverd, afhankelijk van het feit of de stapel s vol is of niet.
    * Gebruikt: /
BEGIN
    RETOUR (data.length - 1 = t)
EINDE

Oefening 5.6.4

size(I: /): aantal: geheel getal
    * Preconditie: de stapel s bestaat
    * Postconditie: het aantal elementen van de stapel s werd geretourneerd
    * Gebruikt: /
BEGIN
    RETOUR (t + 1)
EINDE

Oefening 5.6.5

pushOptimized(I: x: Element): /
    * Preconditie:
    * Postconditie:
    * Gebruikt: /
BEGIN
    ALS (t = data.length - 1) DAN
        data2 <- nieuwe array[data.length * 2]

        VOOR i = 0 TOT t DOE
            data2[i] <- data[i]
        EINDE VOOR

        data <- data2
    EINDE ALS

    t <- t + 1
    data[t] <- x

    RETOUR data
EINDE