Chapter 10 | Data Types & Structures

10.1 Data Types and Records

Data Types →

Integer: A whole number without a decimal point.

Real: A whole number with a decimal point.

Char:A single letter, digit, or symbol.

String: A sequence of characters that represents text or any other data.

Boolean: A data type that represents true or false values.

Date: A data type that is used to represent dates in a computer system

Records →

10.2 Arrays

Technical terms associated with arrays →

Declaring an array in pseudocode→

DECLARE <identifier> : ARRAY[<lowerbound>:<upperbound>] OF <datatype>

Bubble Sort →


swapflag = true
WHILE swapflag == true
    swapflag = false
    position = 0
    FOR position = 0 to length_of_list
        compare(current_item , next_item)
        IF (current_item > next_item)
            swap(current_item, next_item)
            swapflag = true
        ENDIF
        position = position + 1
    ENDFOR
ENDWHILE
      

Linear Search →

position = 0
INPUT SearchValue
Length = array.length - 1
WHILE position < length AND array[position] != SearchValue
    position = position + 1
ENDWHILE
IF position > length
    OUTPUT “Value not found”
ELSE 
    OUTPUT “Item found at position” + position 
ENDIF
      

10.3 Files

Why are files needed →

Pseudocode to Open a Text File →

WRITEFILE <file identifier>, <string></string>

Pseudocode to Read From a Text File →

READFILE <file identifier>, <variable>

Pseudocode to Append a Text File →

WRITEFILE <file identifier>, <string>

Pseudocode to Close File →

CLOSEFILE <file identifier>

Pseudocode to Test Whether the File Pointer is at the End of The File:

EOF (<file identifier>)

10.4 Introduction to Abstract Data Types (ADT)

An Abstract Data Type (ADT) is a collection of data and a set of associated operations:

Stacks →

Key Features of a Stack →

Key Features of a Stack →

Methods Used for Stacks →

Queues →

Key Features of a Queue →

Uses of Queues →

Methods Used for Queues →

Implementing a Queue Using an Array →

Linked Lists →

Key Features of a Linked List →

Inserting to an Ordered List →

PROCEDURE InsertInOrder(MyList, data)
    DECLARE NewNode : Node
    NewNode.data = data
    CurrentNode = MyList.head

    IF CurrentNode == NULL THEN
        MyList.head = NewNode
    ELSE 
        IF NewNode.data  current.data THEN
            NewNode.pointer = MyList.head
            MyList.head = NewNode
        ELSE
            WHILE (current.pointer != NULL AND current.next.data < NewNode.data)
                Current = current.next
            ENDWHILE 
            NewNode.next = current.next
            Current.next = NewNode
        ENDIF
    ENDIF
ENDPROCEDURE
      

Traversing a Linked List→

PROCEDURE traverse (MyList)
    CurrentNode = MyList.head
    WHILE CurrentNode != NULL
        OUTPUT(CurrentNode.data)
        CurrentNode = CurrentNode.next
    ENDWHILE
ENDPROCEDURE
        
      

Deleteing From a Linked List→

PROCEDURE delete(MyList, data)
    current = MyList.head

    IF current.data == data THEN
        MyList.head = current.head
    ELSE
        WHILE current.next.data != data THEN
            Current = current.next
        ENDWHILE
        current.next = current.next.next
    ENDIF
ENDPROCEDURE
      

Implementing a Linked List using an array →

<identifier>