1 / 31

מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע (

מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע (. ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון. שלום!. המייל של אבי: rosenfa@gmail.com המייל של אריאלה: ariellarich@gmail.com כתובת האתר: www.jct.ac.il/~rosenfa/ibud סילאבוס הקורס: www.jct.ac.il/~rosenfa/ibud/syllabus.htm. מה לומדים?. מבנה נתונים

Download Presentation

מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע (

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. מבנה נתונים ואלגוריתמים) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון

  2. שלום! • המייל של אבי: rosenfa@gmail.com • המייל של אריאלה: ariellarich@gmail.com • כתובת האתר: www.jct.ac.il/~rosenfa/ibud • סילאבוס הקורס: www.jct.ac.il/~rosenfa/ibud/syllabus.htm

  3. מה לומדים? • מבנה נתונים • אלגוריתמים • תכנות WINDOWS

  4. דרישות הקורס • חשיבה! • דרך ארץ! • (אין חובת נוכחות!) • תרגילים – 20% • מבחן – 80%

  5. מערכים

  6. והנה בעיה כתוב תוכנית אשר תקלוט 36 מספרים ותדפיס כמה מתוכם גדולים יותר מהממוצע. מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו

  7. בעיה ? מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו

  8. הגדרת מערך מערכים Arrays Dim שם (גודל) As סוג Dim A (9) As Integer אבל יש כאן 10 תאים! הגדרת מערך לדוגמא מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו

  9. מערכים Arrays Dim A (9) As Integer 7 A[5]? 9 -4 0 3 6 7 1 7 5 -2 מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו

  10. מספר כללים מערכים Arrays • מספור התאים - החל מאפס • האינדקס חייב להיות בתחום מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו

  11. מערכים Arrays שימו לב להבדל I A(I) אינדקס תוכן מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו

  12. moshe david avi gad yossi yair מערך של מחרוזות מערכים Arrays Dim A (5) As String מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו

  13. moshe david avi gad yossi yair מערכים Arrays Len(a(2)) 3 Mid(a(1),2,3) avi a(2) + a(4) gadyair מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו

  14. דוגמא Module Module1 Sub Main() Dim x(10) As Integer Dim i As Integer Dim num As New Random() For i = 0 To 10 'Why 10? x(i) = num.Next(1, 10) Next For i = 0 To 10 Console.WriteLine(x(i)) Next End Sub End Module

  15. תרגיל כיתה: יש לקלוט 10 מספרים למערך ולהדפיס את הסכום והערך המקסימלי. Module Module1 Sub Main() Dim x(10) As Integer Dim i As Integer For i = 1 To 10 'Why not 0? x(i) = Console.ReadLine() Next Dim sum As Integer = 0 Dim max = x(1) For i = 1 To 10 sum += x(i) If (x(i) > max) Then max = x(i) End If Next Console.WriteLine(sum) Console.WriteLine("Max is {0} ", max) End Sub End Module

  16. תרגיל כיתה:יש לקלוט 10מספרים למערך. להוסיף לכל מספר את המספר שבא אחריו במערך. למספר האחרון במערך לא להוסיף דבר. יש להדפיס את המערך. Module Module1 Sub Main() Dim x(10) As Integer Dim i As Integer For i = 0 To 9 'Why not 10? x(i) = Console.ReadLine() Next For i = 0 To 9 x(i) = x(i) + x(i + 1) Next For i = 0 To 9 Console.WriteLine("In position {0} I have {1} ", i, x(i)) Next End Sub End Module

  17. שיפורים... Module Module1 Sub Main() Dim x(10) As Integer Dim i As Integer Dim len As Integer = x.Length() Console.WriteLine("Length is {0} ", len) For i = 0 To len - 1 'Familiar? x(i) = Console.ReadLine() Next For i = 0 To len - 2 'why - 2? x(i) = x(i) + x(i + 1) Next For i = 0 To len - 1 Console.WriteLine("In position {0} I have {1} ", i, x(i)) Next End Sub End Module

  18. פונקציות קיימות... Module Module1 Sub Main() Dim x() As Integer = {1, 7, 5, 50, -1} Console.WriteLine("Length is {0} ", x.Length()) Console.WriteLine("Position 0 is {0} ", x(0)) Array.Resize(x, 10) Console.WriteLine("Length is {0} ", x.Length()) Console.WriteLine("Position 0 is {0} ", x(0)) Console.WriteLine("But position 9 is {0} ", x(9)) Array.Sort(x) Console.WriteLine("Position 0 is {0} ", x(0)) End Sub End Module

  19. פלט Length is 5 Position 0 is 1 Length is 10 Position 0 is 1 But position 9 is 0 Position 0 is -1

  20. והנה בעיה כתוב תוכנית אשר תקלוט מספר לא ידוע של מספרים ותדפיס ... מבוא לתכנות לתו"נ- שבוע מספר 11- אבי רוזנפלד - סמסטר ב' – תש"ע

  21. בעיה ? מבוא לתכנות לתו"נ- שבוע מספר 11- אבי רוזנפלד - סמסטר ב' – תש"ע

  22. מערך דינמי Module Module1 Sub Main() Dim x() As Integer = {} Dim answer As String = "yes" While (answer = "yes") Console.WriteLine("Do you want another number?") answer = Console.ReadLine() If (answer = "yes") Then Array.Resize(x, x.Length + 1) Console.WriteLine("Size is now " & x.Length) Console.WriteLine("Now Enter a value") x(x.Length - 1) = Console.ReadLine() End If End While Dim i As Integer For i = 0 To x.Length - 1 Console.WriteLine("In position {0} I have {1} ", i, x(i)) Next End Sub End Module

  23. מערך דינמי - פלט Do you want another number? yes Size is now 1 Now Enter a value 33 Do you want another number? yes Size is now 2 Now Enter a value 45 Do you want another number? no In position 0 I have 33 In position 1 I have 45

  24. פונקציות – דוגמא 1 Module Module1 Function Max(ByVal x() As Integer) As Integer Dim temp As Integer = x(0) Dim i As Integer For i = 1 To x.Length - 1 If x(i) > temp Then temp = x(i) End If Next Return temp End Function Sub Main() Dim x() As Integer = {1, 7, 5, 50, -1, 0, 100, -2} Console.WriteLine("The max is " & Max(x)) End Sub End Module The max is 100 פלט:

  25. פונקציות – דוגמא 2 Module Module1 Sub Print(ByVal x() As Integer) Dim len As Integer = x.Length - 1 Dim i As Integer Console.WriteLine("Begin the Print Array Sub") For i = 0 To len Console.WriteLine("In position {0} I have {1} ", i, x(i)) Next Console.WriteLine("End of the Print Array Sub") End Sub Sub Main() Dim x() As Integer = {1, 7, 5, 50, -1} Print(x) Array.Resize(x, 10) Print(x) Array.Sort(x) Print(x) Array.Reverse(x) Print(x) End Sub End Module

  26. המשך דוגמא 2 - פלט Begin the Print Array Sub In position 0 I have 1 In position 1 I have 7 In position 2 I have 5 In position 3 I have 50 In position 4 I have -1 End of the Print Array Sub Begin the Print Array Sub In position 0 I have 1 In position 1 I have 7 In position 2 I have 5 In position 3 I have 50 In position 4 I have -1 In position 5 I have 0 In position 6 I have 0 In position 7 I have 0 In position 8 I have 0 In position 9 I have 0 End of the Print Array Sub Begin the Print Array Sub In position 0 I have -1 In position 1 I have 0 In position 2 I have 0 In position 3 I have 0 In position 4 I have 0 In position 5 I have 0 In position 6 I have 1 In position 7 I have 5 In position 8 I have 7 In position 9 I have 50 End of the Print Array Sub Begin the Print Array Sub In position 0 I have 50 In position 1 I have 7 In position 2 I have 5 In position 3 I have 1 In position 4 I have 0 In position 5 I have 0 In position 6 I have 0 In position 7 I have 0 In position 8 I have 0 In position 9 I have -1 End of the Print Array Sub

  27. פונקציות – דוגמא 3 Sub Print(ByVal x() As Integer) Dim i As Integer Console.WriteLine() Console.WriteLine("Now printing the array") For i = 0 To x.Length() - 1 'why -1 ??? Console.Write(x(i) & " ") If (i + 1) Mod 15 = 0 Then Console.WriteLine("") Next End Sub

  28. המשך דוגמא 3 - שימוש בפונקציה Sub Main() Dim i As Integer Dim targetArray(100) As Integer Dim rand As New Random For i = 0 To 100 targetArray(i) = rand.Next(-1000, 1000) Next ' Sort the entire targetArray. Array.Sort(targetArray) Print(targetArray) Array.Reverse(targetArray) Print(targetArray) Array.Resize(targetArray, 10) Array.Sort(targetArray) Print(targetArray) Console.WriteLine(vbNewLine) End Sub

  29. המשך דוגמא 3 - פלט Now printing the array -996 -934 -917 -881 -870 -851 -848 -824 -818 -807 -791 -786 -778 -709 -704 -666 -642 -618 -617 -597 -580 -509 -477 -426 -418 -403 -394 -354 -346 -337 -317 -299 -289 -276 -253 -232 -231 -200 -193 -157 -124 -120 -74 -73 -72 -69 -59 -1 20 23 24 113 140 198 228 262 264 272 315 322 324 404 408 408 453 467 479 495 498 513 519 544 554 570 572 584 597 619 633 642 684 703 704 720 731 737 739 776 778 786 798 842 864 876 884 904 971 974 974 997 998 Now printing the array 998 997 974 974 971 904 884 876 864 842 798 786 778 776 739 737 731 720 704 703 684 642 633 619 597 584 572 570 554 544 519 513 498 495 479 467 453 408 408 404 324 322 315 272 264 262 228 198 140 113 24 23 20 -1 -59 -69 -72 -73 -74 -120 -124 -157 -193 -200 -231 -232 -253 -276 -289 -299 -317 -337 -346 -354 -394 -403 -418 -426 -477 -509 -580 -597 -617 -618 -642 -666 -704 -709 -778 -786 -791 -807 -818 -824 -848 -851 -870 -881 -917 -934 -996 Now printing the array 842 864 876 884 904 971 974 974 997 998

  30. פונקציות בוליאנית Module Module1 Function Flip(ByVal word1 As String) As Boolean Dim i As Integer For i = 0 To word1.Length() - 1 If word1(i) <> word1(word1.Length() - 1 - i) Then Return False End If Next Return True End Function Sub Main() Dim a, b As String a = Console.ReadLine If (Flip(a)) Then Console.WriteLine("It is a palindrome") Else Console.WriteLine("It isn't") End If End Sub End Module

  31. עוד דרך לשנות את גודל המערך Module Module1 Sub Main() Dim x() As Integer = {1, 2, 53, 3, 1, 23} Print(x) ReDim Preserve x(10) Print(x) ReDim x(15) Print(x) End Sub End Module פלט: Now printing the array 1 2 53 3 1 23 Now printing the array 1 2 53 3 1 23 0 0 0 0 0 Now printing the array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

More Related