<?xml version="1.0"?>
<flowgorithm fileversion="2.6">
    <attributes>
        <attribute name="name" value=""/>
        <attribute name="authors" value="Sassmaster"/>
        <attribute name="about" value=""/>
        <attribute name="saved" value="2017-10-25 02:27:25 PM"/>
        <attribute name="created" value="U2Fzc21hc3RlcjsgU0FTU01BU1RFUjsgMjAxNy0wNC0wMzsgMTI6MDM6MjIgUE07IDMyMDM="/>
        <attribute name="edited" value="RGFtaWFuOyBEQU1JQU4tUEM7IDIwMTctMTAtMjU7IDAyOjI3OjI1IFBNOyAyNTgw"/>
    </attributes>
    <function name="Main" type="None" variable="">
        <parameters/>
        <body>
            <declare name="size" type="Integer" array="False" size=""/>
            <assign variable="SIZE" expression="6"/>
            <declare name="names" type="String" array="True" size="SIZE"/>
            <assign variable="names[0]" expression="&quot;Hall&quot;"/>
            <assign variable="names[1]" expression="&quot;Harrison&quot;"/>
            <assign variable="names[2]" expression="&quot;Hoyle&quot;"/>
            <assign variable="names[3]" expression="&quot;Kimura&quot;"/>
            <assign variable="names[4]" expression="&quot;Lopez&quot;"/>
            <assign variable="names[5]" expression="&quot;Pike&quot;"/>
            <declare name="phones" type="String" array="True" size="SIZE"/>
            <assign variable="phones[0]" expression="&quot;555-6783&quot;"/>
            <assign variable="phones[1]" expression="&quot;555-0199&quot;"/>
            <assign variable="phones[2]" expression="&quot;555-9974&quot;"/>
            <assign variable="phones[3]" expression="&quot;555-2377&quot;"/>
            <assign variable="phones[4]" expression="&quot;555-7772&quot;"/>
            <assign variable="phones[5]" expression="&quot;555-1716&quot;"/>
            <declare name="searchName" type="String" array="False" size=""/>
            <declare name="index" type="Integer" array="False" size=""/>
            <declare name="again" type="String" array="False" size=""/>
            <assign variable="again" expression="&quot;Y&quot;"/>
            <while expression="again == &quot;Y&quot; OR again == &quot;y&quot;">
                <output expression="&quot;Enter a last name to search for.&quot;"/>
                <input variable="searchName"/>
                <declare name="phoneNumber" type="Integer" array="False" size=""/>
                <assign variable="phoneNumber" expression="binarySearch(Names,searchName,Size)"/>
                <if expression="phoneNumber == -1">
                    <then>
                        <output expression="&quot;Not found&quot;"/>
                    </then>
                    <else>
                        <output expression="&quot;The phone number is &quot; &amp;phones[phoneNumber]"/>
                    </else>
                </if>
                <output expression="&quot;Do you want to search again Y/N&quot;"/>
                <input variable="again"/>
            </while>
        </body>
    </function>
    <function name="binarySearch" type="Integer" variable="position">
        <parameters>
            <parameter name="names" type="String" array="True"/>
            <parameter name="searchName" type="String" array="False"/>
            <parameter name="SIZE" type="Integer" array="False"/>
        </parameters>
        <body>
            <declare name="first" type="Integer" array="False" size=""/>
            <assign variable="first" expression="0"/>
            <declare name="last" type="Integer" array="False" size=""/>
            <comment text="Remember it's a 0 indexed array so you need to take one off it otherwise you will get problems later"/>
            <assign variable="last" expression="SIZE-1"/>
            <declare name="position" type="Integer" array="False" size=""/>
            <assign variable="position" expression="-1"/>
            <declare name="found" type="Boolean" array="False" size=""/>
            <assign variable="found" expression="false"/>
            <declare name="middle" type="Integer" array="False" size=""/>
            <while expression="(NOT found) AND (first &lt;=last)">
                <assign variable="middle" expression="Abs((first+last) / 2)"/>
                <if expression="names[middle] == searchName">
                    <then>
                        <assign variable="found" expression="true"/>
                        <assign variable="position" expression="middle"/>
                    </then>
                    <else>
                        <if expression="names[middle] &gt; searchName">
                            <then>
                                <assign variable="last" expression="middle -1"/>
                            </then>
                            <else>
                                <assign variable="first" expression="middle +1"/>
                            </else>
                        </if>
                    </else>
                </if>
            </while>
        </body>
    </function>
</flowgorithm>
