1 / 8

רשימה מקושרת Linked Lists

רשימה מקושרת Linked Lists. דוגמא. STRING איך עושים Dim x as String בלי לדעת מראש את הגודל!. A. C. B. A. Linked Lists. A linked list is a series of connected nodes Each node contains at least A piece of data (any type) Pointer to the next node in the list

hanne
Télécharger la présentation

רשימה מקושרת Linked Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. רשימה מקושרתLinked Lists

  2. דוגמא • STRING • איך עושים Dim x as String בלי לדעת מראש את הגודל!

  3. A C B A Linked Lists • A linked listis a series of connected nodes • Each node contains at least • A piece of data (any type) • Pointer to the next node in the list • Head: pointer to the first node • The last node points to NULL  Head node www.cs.ust.hk/~qyang/171/linked-list.ppt data pointer

  4. על מה בנוי רשימה מקושרת? • קדקוד (NODE או LINK) • המידע ששומרים (או אוסף המידע) • קישור לקדקוד הבא (מידי פעם גם לקדקוד הקודם) • מחלקה לניהול הקדקודים (LINKED LIST) • פונקציית בנאי (CONSTRUCTOR) • שמירת מקום של הקודקוד הראשון • פונקציית עזר (PRINT, ADD, DELETE, וכו')

  5. דוגמא של LINK PublicClassLink Privatem_MyDataAsString Privatem_NextLinkAsLink PublicSubNew(ByValmyParentAsLink, ByValtheDataAsString) m_MyData = theData myParent.m_NextLink = Me EndSub PublicSubNew(ByValtheDataAsString) m_MyData = theData EndSub FunctionMyData() AsString Returnm_MyData EndFunction FunctionNextLink() AsLink Returnm_NextLink EndFunction EndClass

  6. דוגמא של LINKEDLIST PublicClassLinkedList Private m_CurrentLink AsLink Private m_FirstLink AsLink Private Size AsInteger PublicSubNew(ByVal theData AsString) m_CurrentLink = NewLink(theData) m_FirstLink = m_CurrentLink Size = 1 EndSub PublicFunction MakeLink(ByVal currentLink AsLink, ByVal theData AsString) AsLink m_CurrentLink = NewLink(currentLink, theData) Size = Size + 1 Return m_CurrentLink EndFunction Function GetNextLink(ByVal aLink AsLink) AsLink Return aLink.NextLink() EndFunction Function GetCurrentLink() AsLink Return m_CurrentLink EndFunction Function GetFirstLink() AsLink Return m_FirstLink EndFunction PublicSub PrintAll() Dim i AsInteger Dim temp AsLink = m_FirstLink For i = 0 To Size - 1 Console.WriteLine("Contents of Place " & i & " is :") Console.WriteLine(temp.MyData) temp = temp.NextLink Next EndSub EndClass

  7. שימוש במחלקה (MAIN) ModuleModule1 Sub Main() Dim List AsNewLinkedList("Avi") Dim aLink AsLink = List.GetCurrentLink aLink = List.MakeLink(aLink, "Bob") aLink = List.MakeLink(aLink, "Chaim") List.PrintAll() EndSub EndModule

  8. שיפורים??? • להדפיס טווח של קדקודים • להדפיס את הרשימה בסדר יורד • חיפוש אחרי מידע (ולהחזיר את התא או התאים שבו הוא נמצא • שינוי של הNODE להכניס כמה סוגי מידע • איך????????????

More Related