שימוש במערך דינמי : ArrayList. מאפיינים חשובים בכל LIST יכולת להכניס מידע בלי תלות בטיפוס יכולת למחוק מידע יכולת להוסיף מידע פונקציות נוספות ( מיון, חיפוש.

Slides:



Advertisements
Similar presentations
Stacks and Queues. Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about.
Advertisements

תרגול 8 Skip Lists Hash Tables. Skip Lists Definition: – A skip list is a probabilistic data structure where elements are kept sorted by key. – It allows.
1 Generic Collections Chapter Objectives You will be able to Use generic collection classes available in the.NET framework.
מבוא למדעי המחשב לתעשייה וניהול דוגמאות ותרגול נוסף במערך חד ממדי הרצאה 12.
מחרוזות של תווים. מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו מחרוזות - Strings Dim s As String s = “hello” s = s & “kita” או s =
רשימה מקושרת Linked Lists. דוגמא STRING איך עושים Dim x as String בלי לדעת מראש את הגודל !
חורף - תשס " ג DBMS, Design1 שימור תלויות אינטואיציה : כל תלות פונקציונלית שהתקיימה בסכמה המקורית מתקיימת גם בסכמה המפורקת. מטרה : כאשר מעדכנים.
חורף - תשס " ג DBMS, צורות נורמליות 1 צורה נורמלית שלישית - 3NF הגדרה : תהי R סכמה רלציונית ותהי F קבוצת תלויות פונקציונליות מעל R. R היא ב -3NF.
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
אלגוריתמים, WINDOWS והחיים. מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 7 מיוןsort.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
תכנות תרגול 14 שבוע:
מערכים מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו והנה בעיה כתוב תוכנית אשר תקלוט 36 מספרים ותדפיס כמה מתוכם גדולים יותר מהממוצע.
1 Data Structures, CS, TAU, Perfect Hashing בעיה: נתונה קבוצה S של n מפתחות מתחום U השוואה ל- Hash : * טבלה קבועה (Hash רגיל - דינאמי) * רוצים זמן קבוע.
Stacks and Queues. Stack ADT סוג של מערך מוגבל מהר מאוד ולוקחים מעט זכרון שימוש ב LIFO – LIFO (Last In, First Out) lists. –אפשר להוסיף רק בסוף הרשימה.
C# Programming: From Problem Analysis to Program Design1 Advanced Collections C# Programming: From Problem Analysis to Program Design 3 rd Edition 8.
אלגוריתמי חיפוש. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To.
תכנות מונחה עצמים Object Oriented Programming (OOP) אתגר מחזור ב' Templates תבניות.
פתרון תרגילים #9. דוגמה פשוטה #1 Module Module1 Sub Main() Dim x As String x = Console.ReadLine For i = 1 To x.Length() - 1 Step 2 Console.WriteLine(x(i))
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
מערכים דו ממדי ו STRUCTS פונקציות בוליאנית Module Module1 Function Flip(ByVal word1 As String) As Boolean Dim i As Integer For i = 0 To word1.Length()
1 מבוא למדעי המחשב סיבוכיות. 2 סיבוכיות - מוטיבציה סידרת פיבונאצ'י: long fibonacci (int n) { if (n == 1 || n == 2) return 1; else return (fibonacci(n-1)
Safari On-line books. מה זה ספארי ספארי זו ספריה וירטואלית בנושא מחשבים היא כוללת יותר מ כותרים כל הספרים הם בטקסט מלא ניתן לחפש ספר בנושא מסוים.
תכנות תרגול 12 שבוע : מבנים מטרת המבנים היא לאפשר למתכנת להגדיר טיפוסי משתנים חדשים אשר מתאימים ספציפית לבעיה שאותה התוכנית פותרת. מטרת המבנים.
אביב תשס " ה JCT תיכון תוכנה ד " ר ר ' גלנט / י ' לויאןכל הזכויות שמורות 1 פרק 7 ISP דוגמא נוספת.
2-4 tree k=2 Each node has 2,3,or 4 children. Delete delete(14,T)
Java Collections. Collections, Iterators, Algorithms CollectionsIteratorsAlgorithms.
Lists, Stacks, Queues Svetlin Nakov Telerik Corporation
Structure. מה לומדים היום ? דרך לבנות מבנה נתונים בסיסי – Structure מייצר " טיפוס " חדש מתאים כאשר רוצים לאגד כמה משתנים יחד דוגמאות : עובד : שם, טלפון,
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
פיתוח מערכות מידע Class diagrams Aggregation, Composition and Generalization.
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
בתרגול הקודם כללי הרשאות (Visibility modifiers) בהורשה – Public – Protected – private חוקי גישה לשדות ושיטות בהורשה ב -Java מחלקות אבסטרקטיות –המילה השמורה.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
1 מבוא למדעי המחשב הרצאה 21: Queue, Iterator & Iterable.
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
מבוא למדעי המחשב לתעשייה וניהול הרצאה 7. סברוטינות subroutines.
Windows Database Applications CIS 341 Chapter 11.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Arrays and Collections Tonga Institute of Higher Education.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
Introduction to the Standard Template Library (STL) A container class holds a number of similar objects. Examples: –Vector –List –Stack –Queue –Set –Map.
מחסנית ותור Stacks and Queues. מחסנית Stack מחסנית - Stack ADT סוג של מערך מוגבל מהיר מאוד ותופס מעט זיכרון שימוש ב LIFO – LIFO (Last In, First Out)
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
Costs and Filters Dr. Avi Rosenfeld Department of Industrial Engineering Jerusalem College of Technology
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
מבוא למדעי המחשב לתעשייה וניהול הרצאה 12. ספריות.
מחסנית ותור Stacks and Queues. מחסנית Stack מחסנית - Stack ADT סוג של מערך מוגבל מהיר מאוד ותופס מעט זיכרון שימוש ב LIFO – LIFO (Last In, First Out)
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Data-structure-palooza Checkout DataStructures from SVN.
Generics & Collection Classes Version 1.0. Topics Generic Methods and Classes Generic Collection Classes List Enumerators Queue Stack LinkedList.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
AUC Technologies Projects Consulting, Development, Mentoring, and Training Company Collections Presented By : Muhammad Atif Hussain Deputy Manager IT (Takaful.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
אלגוריתמי חיפוש. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To.
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
מבני נתונים רשימה מקושרת, מחסנית ותור
מבוא למדעי המחשב לתעשייה וניהול
מחלקות classes.
מבוא למדעי המחשב סיבוכיות.
HW-6 Deadline Extended to April 27th
תירגול 14: מבני נתונים דינאמיים
הרצאה 06 רשימות מקושרות קרן כליף.
עבודה עם נתונים באמצעות ADO.NET
ממשקים - interfaces איך לאפשר "הורשה מרובה".
מחסנית ותור Stacks and Queues.
Basic Collections.
Presentation transcript:

שימוש במערך דינמי : ArrayList

מאפיינים חשובים בכל LIST יכולת להכניס מידע בלי תלות בטיפוס יכולת למחוק מידע יכולת להוסיף מידע פונקציות נוספות ( מיון, חיפוש וכו ')

שימוש בסיסי ב ARRAYLIST Module Module1 Sub Main() Dim ItemList As New ArrayList() 'No datatype OR length! ItemList.Add("Item4") ItemList.Add("Item5") ItemList.Add("Item2") ItemList.Add("Item1") ItemList.Add("Item3") ItemList.Insert(3, "Item6") 'insert after position 2 (into pos 3) ItemList.Sort() 'sort items in an arraylist ItemList.Reverse() ' reverses ItemList.Remove("Item1") 'remove based on value ItemList.RemoveAt(2) 'removes based on position Console.WriteLine("Where is Item5? " & ItemList.IndexOf("Item5")) End Sub End Module

נוסיף פונקציית הדפסה Sub Print(ByVal x As ArrayList) Dim i As Integer Console.WriteLine("Shows Added Items") For i = 0 To x.Count() - 1 Console.WriteLine(x(i)) Next End Sub

שימוש בסיסי ב ARRAYLIST, והדפסת התוכן Sub Main() Dim ItemList As New ArrayList() 'No datatype OR length! ItemList.Add("Item4") ItemList.Add("Item5") ItemList.Add("Item2") ItemList.Add("Item1") ItemList.Add("Item3") Print(ItemList) ItemList.Insert(3, "Item6") 'insert after pos 2(into pos 3) Print(ItemList) ItemList.Sort() 'sort items in an arraylist Print(ItemList) ItemList.Reverse() ' reverses Print(ItemList) ItemList.Remove("Item1") 'remove based on value Print(ItemList) ItemList.RemoveAt(2) 'removes based on position Print(ItemList) Console.WriteLine("Where is Item5? " & ItemList.IndexOf("Item5")) End Sub

הפלט Shows Added Items Item4 Item5 Item2 Item1 Item3 Shows Added Items Item4 Item5 Item2 Item6 Item1 Item3 Shows Added Items Item1 Item2 Item3 Item4 Item5 Item  Shows Added Items Item6 Item5 Item4 Item3 Item2 Item1 Shows Added Items Item6 Item5 Item4 Item3 Item2 Shows Added Items Item6 Item5 Item3 Item2 Where is Item5? 1

ArrayList מאפשר הגדרת מערך בלי סוג או אורך ! Sub Main() Dim ItemList As New ArrayList() 'No datatype OR length! ItemList.Add("Item4") ItemList.Add("Item5") ItemList.Add("Item2") ItemList.Add("Item1") ItemList.Add("Item3") Print(ItemList) ItemList.Insert(3, "Item6") 'insert after pos 2(into pos 3) Print(ItemList) ItemList.Sort() 'sort items in an arraylist Print(ItemList) ItemList.Reverse() ' reverses Print(ItemList) ItemList.Remove("Item1") 'remove based on value Print(ItemList) ItemList.RemoveAt(2) 'removes based on position Print(ItemList) Console.WriteLine("Where is Item5? " & ItemList.IndexOf("Item5")) End Sub

ניזכר ב structure Structure Oved Dim name As String Dim maskoret As Integer End Structure Sub PrintOved(ByVal x As ArrayList) Dim i As Integer Console.WriteLine("Shows Added Items") For i = 0 To x.Count() - 1 Console.WriteLine(x(i).name) Console.WriteLine(x(i).maskoret) Next End Sub

שימוש ב STRUCTURE עם ARRAYLIST Module Module1 Sub Main() Dim array1 As New ArrayList() 'No datatype OR length! Dim ans As String = "yes" Dim item As Oved While ans = "yes" Console.WriteLine("Enter name, maskoret, and if again (yes):") item.name = Console.ReadLine() item.maskoret = Console.ReadLine() array1.Add(item) ans = Console.ReadLine() End While PrintOved(array1) End Sub End Module

שימוש ב INSERT Module Module1 Sub Main() Dim ItemList As New ArrayList() 'No datatype OR length! ItemList.Add(15) ItemList.Add(5) ItemList.Add(13) ItemList.Insert(1, 6) 'insert an item after position 0 (into pos 1) Print(ItemList) End Sub Sub Print(ByVal x As ArrayList) Dim i As Integer Console.WriteLine("Shows ALL Items") For i = 0 To x.Count() - 1 Console.WriteLine(x(i)) Next End Sub End Module

מוסג של ByRef- אין RETURN! Module Module1 Sub Swap(ByRef x As Integer, ByRef y As Integer) Dim temp As Integer = x x = y y = temp End Sub Sub Main() Dim a As Integer = 3, b As Integer = 4 Console.WriteLine("A is " & a & " b is " & b) Swap(a, b) 'No return!!! Console.WriteLine("A is " & a & " b is " & b) End Sub End Module

השוואה למערך - שימוש במערך במקום ArrayList Module Module1 Sub Main() Dim ItemList(0) As Integer 'With datatype AND length! Console.WriteLine(ItemList.Length()) ItemList(0) = 15 Array.Resize(ItemList, ItemList.Length() + 1) ItemList(1) = 5 Array.Resize(ItemList, ItemList.Length() + 1) ItemList(2) = 13 PrintArr(ItemList) InsertToArr(ItemList, 1, 6) PrintArr(ItemList) End Sub המשך.....

השוואה למערך - שינויים והוספות בפונקציות המשך... Sub PrintArr(ByVal x() As Integer) Dim i As Integer Console.WriteLine("Shows Added Items") For i = 0 To x.Count() - 1 Console.WriteLine(x(i)) Next End Sub Sub InsertToArr(ByRef x() As Integer, ByVal place As Integer, ByVal value As Integer) Array.Resize(x, x.Length() + 1) Dim index As Integer For index = x.Length - 1 To place Step -1 x(index) = x(index - 1) Next x(place) = value End Sub End Module

Collections מבני נתונים לאוסף נתונים Array List Sorted List Hash Table Stack Queue These can be accessed via the System.Collections namespace

Stack - מחסנית מבנה נתונים שבו הנתונים נשלפים בסדר הפוך לסדר שבו הוכנסו מממש אלגוריתם של LIFO (Last In First Out) הוספת איבר ע " י פונקציה בשם Push() שליפת איבר ע " י פונקציה בשם Push()

Queue - תור מבנה נתונים שבו הנתונים נשלפים באותו סדר שבו הוכנסו מממש אלגוריתם של FIFO (First In First Out) הוספת איבר ע " י פונקציה בשם Enqueue() שליפת איבר ע " י פונקציה בשם Dequeue()

ArrayList, Stack, Queue מה יותר טוב או מהר ?! ה ArrayList הוא אובייקט יותר מתקדם –פונקציות חדשות ArrayList מבוסס על רשימה מקושרת יש גם וריאציות שונות של STACK / QUEUE –נלמד בהמשך

Array List ArrayList הוא מערך דינמי כאשר מוסיפים אלמנט הוא גדל חיפוש מבוסס על האינדקס חיפוש סדרתי מבוסס על איברים –לכן מאד איטי חסכוני במקום

Sorted List איברים נשמרים כזוג של –מפתח וערך (key value pairs) המיון היא לפי המפתח חיפוש אפשרי לפי האינדקס או המפתח –מהיר יותר מ ArrayList תפיסת מקום בינונית אסור שהמפתח יהיה כפול או ריק ערכים יכולים להיות כפולים או ריקים

Hash Table איברים נשמרים כזוג של –מפתח וערך (key value pairs) השמירה היא לפי המפתח חיפוש מבוסס על המפתח –מהיר מאד תפיסת המון מקום מותר שהמפתח יהיה כפול או ריק

איך עושים את זה ב LINK? Public Class Link Private m_MyData As String Private ID As Integer Private m_NextLink As Link Public Sub New(ByVal myParent As Link, ByVal theData As String, ByVal theID As Integer) m_MyData = theData ID = theID myParent.m_NextLink = Me End Sub Public Sub New(ByVal theData As String, ByVal theID As Integer) m_MyData = theData ID = theID End Sub Function MyData() As String Return m_MyData End Function Function MyID() As Integer Return ID End Function Function NextLink() As Link Return m_NextLink End Function End Class

אבל אז יש צורך לשנות... Public Class LinkedList Private m_CurrentLink As Link Private m_FirstLink As Link Private Size As Integer Public Sub New(ByVal theData As String, ByVal theID As Integer) m_CurrentLink = New Link(theData, theID) m_FirstLink = m_CurrentLink Size = 1 End Sub Public Function MakeLink(ByVal currentLink As Link, ByVal x As String, ByVal theID As Integer) As Link m_CurrentLink = New Link(currentLink, x, theID) Size = Size + 1 Return m_CurrentLink End Function Function GetNextLink(ByVal aLink As Link) As Link Return aLink.NextLink() End Function Function GetCurrentLink() As Link Return m_CurrentLink End Function Function GetFirstLink() As Link Return m_FirstLink End Function

וגם ה MAIN... Module Module1 Sub Main() Dim List As New LinkedList("Avi ", 1) Dim aLink As Link = List.GetCurrentLink aLink = List.MakeLink(aLink, "Bob ", 3) aLink = List.MakeLink(aLink, "Chaim ", -1) aLink = List.MakeLink(aLink, "Dovid ", -5) List.PrintAll() End Sub End Module