How to resolve the algorithm Associative array/Iteration step by step in the Phixmonti programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Associative array/Iteration step by step in the Phixmonti programming language

Table of Contents

Problem Statement

Also show how to iterate just over the keys, or the values, if there is a separate way to do that in your language.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Associative array/Iteration step by step in the Phixmonti programming language

Source code in the phixmonti programming language

include ..\Utilitys.pmt

def getd    /# dict key -- dict data #/
    swap 1 get rot find nip
    dup if
        swap 2 get rot get nip
    else
        drop "Unfound"
    endif
enddef


def setd    /# dict ( key data ) -- dict #/
    1 get var ikey
    2 get var idata
    drop
    1 get ikey find var p drop
    p if
        2 get idata p set 2 set
    else
        2 get idata 0 put 2 set
        1 get ikey 0 put 1 set
    endif
enddef


def pair    /# dict n -- dict ( k d ) #/
    1 over 2 tolist var ikey
    2 swap 2 tolist var idata
    ikey sget
    swap idata sget rot swap
    2 tolist
enddef

def scandict    /# dict n -- dict ( ) #/
    var n
    1 get len nip
    for
        pair
        n if n get nip endif
        print nl
    endfor
enddef

def pairs   /# dict -- dict ( ) #/
    0 scandict  
enddef

def keys
    1 scandict  
enddef

def values
    2 scandict  
enddef

/# ---------- MAIN ---------- #/

( ( ) ( ) )

( "one" 1 ) setd
( 2 "duo" ) setd
( ( 3 4 ) ( 5 "six" ) ) setd

pairs nl
keys nl
values

  

You may also check:How to resolve the algorithm Last letter-first letter step by step in the D programming language
You may also check:How to resolve the algorithm Filter step by step in the Sidef programming language
You may also check:How to resolve the algorithm Append a record to the end of a text file step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm Sorting algorithms/Gnome sort step by step in the C programming language
You may also check:How to resolve the algorithm Stack step by step in the Nanoquery programming language