- Hello:

I have introduced this to my program in order to separate two answer,

with two lines ******* but it is not working.

How can I accomplish this?

Is there another way to do this?

Thank you for you for any inside on this.

for i=40 to 40

call prettyprint "*", i

next i

for i=40 to 40

call prettyprint "*",i

next i

end

sub subprogram prettyprint

sub prettyprint thechar$, n

for i=1 to 40

print thechar$;

next i

print

end sub

'This the program

dim numb(999)

print "Enter the higest value to be stored in numb (less than 1000) "

'I used 593

input answer

answer = answer - 1

for i = 0 to answer

numb(i) = i

next i

print "enter a number to search for: "

input z ' I used 287

call sequentialsearch 999,z,x,y

'Print z; "Number of times table was examined using binary search: ";y

IF x=1 THEN

PRINT z;" was find by using sequential search. ";y;" accesses were

required"

ELSE

PRINT z; " NOT IN TABLE"

END IF

call sortnumb 999

call binarysearch 999,z,x,y

IF x=1 THEN

PRINT z;" was find by using binary search. ";y;" acces were required"

ELSE

PRINT z; " NOT IN TABLE!"

END IF

END

SUB sequentialsearch size,item, BYREF foundit,BYREF hits

hits=0 'initialize hits

foundit =0 'initialize foundit

J=1 'initialize J

WHILE foundit=0 AND J <= size

'While loop is executed as long as entry isn't found

hits=hits+1 'increment count

IF numb(J) = item THEN

foundit=1 'we got it

END IF

J=J+1

WEND

END SUB

SUB binarysearch size,item, BYREF foundit,BYREF hits

' Performs a binary search of size entries in array numb (a global array)

' Input variable size indicates how many entries to search

' Input variable item contains the number to be found in array numb

' variable foundit, returned by reference, is set to 0 if item is not

found, 1 if it is found

' variable hits contains the number of times an entry in numb was searched

' The logic is the same as in sample program on page 288 of your book

hits=0 'initialize hits

left=1

foundit=0

right=size

time2stop=0

WHILE time2stop=0

hits=hits + 1 'increment count

half=INT( (left+right)/2 ) ' calculate index of halfway point

IF item < numb(half) THEN

right=half -1 ' throw away the upper half of the table

ELSE

left=half + 1 'throw away the lower half of the table

END IF

IF item=numb(half) OR left > right THEN 'we got a hit, or its not

there

time2stop=1

END IF

WEND

' fall through wend when we either have a hit, or we've searched the table

IF item=numb(half) THEN 'true if we have a hit

foundit=1

END IF

END SUB

SUB sortnumb size

'sortnumb subroutine sorts in ascending order the size entries in

array numb

FOR i = 1 to size-1

FOR j=i + 1 to size

IF numb(i) > numb(j) THEN 'if out of order switch them

temp=numb(i)

numb(i)=numb(j)

numb(j)=temp

END IF

NEXT j

NEXT i

END SUB > -----Ursprüngliche Nachricht-----

---snip

> Von: libertybasic@yahoogroups.com

>

>

>

There is no need to use a FOR..NEXT loop, where the starting value is the

>

> for i=40 to 40

> call prettyprint "*",i

> next i

> end

>

same as the ending value.

> sub subprogram prettyprint

The incomplete first SUB deffinition should raise an error.

> sub prettyprint thechar$, n

> for i=1 to 40

---snip

> print thechar$;

> next i

> print

> end sub

>

>

You can use LBs SORT command to sort arrays:

>

> SUB sortnumb size

> 'sortnumb subroutine sorts in ascending order the size entries in

> array numb

> FOR i = 1 to size-1

> FOR j=i + 1 to size

> IF numb(i) > numb(j) THEN 'if out of order switch them

> temp=numb(i)

> numb(i)=numb(j)

> numb(j)=temp

> END IF

> NEXT j

> NEXT i

> END SUB

SORT numb(), 1, size

or

SORT numb(), size, 1 '(to reverse the order)

Here is a little function to create a string of one character of a given

length:

'---code start

print string$("*", 40)

end

function string$(character$, number)

for count = 1 to number

string$ = string$ + character$

next

end function

'---code end

---

Stefan Pendl

___________________________________________________________

Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de