home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April B / Pcwk4b98.iso / Borland / Dbase50w / SAMPLES1.PAK / LINKLIST.PRG < prev    next >
Text File  |  1994-08-02  |  2KB  |  79 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Linklist.prg
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         6/93
  7. *
  8. *  UPDATED:      1/94
  9. *
  10. *  VERSION:      dBASE FOR WINDOWS 5.0
  11. *
  12. *  DESCRIPTION:  This program creates a simple linked list of integers
  13. *                from 1 to 10.  Each link in the chain is an instance of the
  14. *                MyList class, which has 2 properties -- value, and next.
  15. *                After the list is created, the function ShowList steps
  16. *                through the list and shows all the links that have been
  17. *                created.
  18. *
  19. *  PARAMETERS:   None
  20. *
  21. *  CALLS:        None
  22. *
  23. *  USAGE:        DO Linklist
  24. *
  25. *******************************************************************************
  26. * environment
  27. private saveLdCheck
  28. saveLdCheck = set("ldCheck")
  29. set ldCheck off
  30.  
  31. * a simple xbase linked-list:
  32. private startList,link,i
  33.  
  34. set talk off
  35. * beginning of the list
  36. startList = new MyList()     && instantiation
  37. link = startList             && link is a temporary reference for
  38.                              && stepping through the list
  39. for i = 1 to 10
  40.    link.val = i
  41.    if i < 10   && don't need an extra instance of the class
  42.       link.next = new MyList() && create a new link
  43.       link = link.next
  44.    endif
  45. next
  46. do ShowList
  47.  
  48. * restore environment
  49. set ldCheck &saveLdCheck
  50.  
  51.  
  52. * class definition for MyList
  53. *******************************************************************************
  54. class MyList
  55. *******************************************************************************
  56.  
  57.    this.val = 0
  58.    this.next = 0
  59.  
  60. endclass
  61.  
  62.  
  63.  
  64.  
  65. *******************************************************************************
  66. function ShowList
  67. *   Displays the linked list created in the main program
  68. *******************************************************************************
  69.  
  70. link = startList  && start at the beginning of the list
  71. do while (.not. empty(link))  && go until no next link in list
  72.    ? link.val
  73.    link = link.next
  74. enddo
  75.  
  76.  
  77.  
  78. **************************** End of Linklist.prg ******************************
  79.