Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 16th, 2008, 03:52 PM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can someone help me with this algorithm please! th

Hi, i've been trying to do this algorithm problem recently but i cant seem to beable to follow the algorithm, It requires me to fill in a table which i can partly complete but dont seem to beable to understand some lines like when i have to push anAarray, could some please help me by seeing what the answers is so i can check if im right or not and could some please translate the algorithm so it is easier to understand so i can trace it properly, any help will be appreciated, thanks!


The procedure PUSH(anArray, top, ch) first adds one to the value of top and then stores the single
character held in ch in the one-dimensional array anArray at anArray[top].

The function POP(anArray, top) returns the character held in anArray[top] and then takes 1 off the
value of top.

The function NEXTCHAR(str) returns the next character in its argument str which is a string.

The functions F(ch), G(ch) and R(ch) take a single character as input and return a value according to the table below.

http://www.imagehosting.com/out.php/...9_untitled.bmp

In the algorithm, & joins two strings together (concatenation).

Code:
1. INPUT aString
2. aString = aString & '')''
3. top = 0
4. PUSH(anArray, top, ''('')
5. newString = '' ''
6. rank = 0
7. current = NEXTCHAR(aString)
8. WHILE current <> '' ''
9. IF top < 1 THEN
10. OUTPUT ''Invalid string''
11. END the procedure
12. ENDIF
13. WHILE F(current) < G(anArray[top])
14. temp = POP(anArray, top)
15. newString = newString & temp
16. rank = rank + R(temp)
17. IF rank < 1 THEN
18. OUTPUT ''Invalid string''
19. END the procedure
20. ENDIF
21. ENDWHILE
22. IF F(current) <> G(anArray[top]) THEN
23. PUSH(anArray, top, current)
24. ELSE
25. POP(anArray, top)
26. ENDIF
27. current = NEXTCHAR(aString)
28. ENDWHILE
29. IF top <> 0 OR rank <> 1 THEN
30. OUTPUT ''Invalid string''
31. ELSE
32. OUTPUT ''Valid string''
33. ENDIF
34. END of procedure
I have to fill in the table below three times by using the three different input strings which are:
CD
p*(q
(v-w)*(x+y)

http://www.imagehosting.com/out.php/..._untitled2.bmp[/url]

you have to work left to write in the table filling it in everytime something changes,

Ive been able to fill in "cd" table which i think is mostly right but im having problem with the other two. its harder then its seems lol. If someone could translate it so its easier to understand, i would be very gratefull. thanks for your help!!


Reply With Quote
  #2 (permalink)  
Old January 16th, 2008, 04:30 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Code:
    Function MyFunc(ByVal aString As String) As String

2.      aString = aString  & ")"
3.      Dim top As Integer  ' Defaults to zero

4.      PUSH(anArray, top, "(")

5.      Dim newString As String
            newString = " "

6.      Dim rank As Integer  ' Defaults to zero

        Dim temp    As String * 1
7.      Dim current As String * 1
            current = NEXTCHAR(aString)

8.      While current <> " "
9.          If top < 1 Then
10.             MyFunc = "Invalid string"
11.             Exit Function
12.         End If

13.         While F(current) < G(anArray[top])  ' I don't see where
                                                ' anArray comes from...
14.             temp = POP(anArray, top)
15.             newString = newString & temp
16.             rank = rank + R(temp)

17.             If rank < 1 Then
18.                 MyFunc = "Invalid string"
19.                 Exit Function
20.             End If

21.         End While

22.         If F(current) <> G(anArray[top]) Then
23.             PUSH(anArray, top, current)
24.         Else
25.             POP(anArray, top)
26.         EndIf

27.         current = NEXTCHAR(aString)

28.     End While

29.     If top <> 0 OR rank <> 1 Then
30.         MyFunc = "Invalid string"
31.     Else
32.         MyFunc = "Valid string"
33.     End If

34. End Function
Perhaps this will help you wade through the algorithm.
Reply With Quote
  #3 (permalink)  
Old January 16th, 2008, 05:05 PM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nope, is it possible to translate it to a more understandable version so i know what im doing at each line of the algorithm?

Reply With Quote
  #4 (permalink)  
Old January 16th, 2008, 07:26 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. we don't do homework ;)

wich line don't you understand?? maybe the best you can do is take the great job that Brian do and add a coment before each lines that tells you what is does...
I think that the desirable here is that you can understand how an algorith work.. in fact you are dealing with a stack.

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
  #5 (permalink)  
Old January 17th, 2008, 04:04 AM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Its not homework, and i dont understand the push function and what to do when i enter the while loop from line 13.

Reply With Quote
  #6 (permalink)  
Old January 17th, 2008, 06:58 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

MMM.. ok...

push put a char in the array at position top... probably push and pop also add or decrease top by 1 (push +1, pop -1)... If that is not true (you never stated that) then your case is solved before start because it will never pass line 9 in any case... (if top < 1 will always be true)...

then the while line compares 2 chars, the input of function f and g.. since you have the 2 inputs the only thing you have to do is look into the table to see what are the results...

and I will never believe that this is not homework ;)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
  #7 (permalink)  
Old January 17th, 2008, 08:02 AM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

really, it aint homework, And this algorithm does work as my friend has completed it and has the correct answer, i just dont know how he did it, i managed to get a answer when i input "cd" but it dosent look right, shall i post the table on here so you can check? ive also got an example but i cant figure out how the algortihm works from the example either.

Reply With Quote
  #8 (permalink)  
Old January 17th, 2008, 08:09 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. did you understand what I wrote before??

what about the pop and push function.. do they do something to top???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
  #9 (permalink)  
Old January 17th, 2008, 09:24 AM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well i know push adds one interger on to top and pop takes one integer off top, Top relate to array indexing i think. array indexing in this algorithm starts at 1.

Reply With Quote
  #10 (permalink)  
Old January 17th, 2008, 09:34 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

You never stated that ;)..

well.. did you understand now how pop and push works?

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
apriori algorithm iralala J2EE 4 January 1st, 2014 05:49 PM
FTC algorithm iralala Java Databases 1 February 3rd, 2009 06:57 AM
algorithm angelboy Other Programming Languages 0 April 14th, 2007 08:56 AM
Typical Algorithm rajanikrishna ASP.NET 1.0 and 1.1 Professional 0 November 20th, 2006 02:05 AM
Algorithm kvanchi General .NET 3 January 20th, 2005 04:28 AM



All times are GMT -4. The time now is 07:18 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.