1 / 8

Datastrukturer og Collections

Datastrukturer og Collections. Oversigt og forskel imellem Jave og . net Collections library Collection interfaces ArrayList IList interface Hashtable Hashtable traversering. Oversigt og forskel imellem J ave og .net. Abstrakte datatyper: lister/sekvenser stak kø

becca
Download Presentation

Datastrukturer og Collections

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. Datastrukturer og Collections • Oversigt og forskel imellem Jave og .net • Collections library • Collection interfaces • ArrayList • IListinterface • Hashtable • Hashtabletraversering Rasmus D. Lehrmann

  2. Oversigt og forskel imellem Jave og .net • Abstrakte datatyper: • lister/sekvenser • stak • kø • Table/Map/Dictionary • Java-specifik: • Collections (generics) • Collection • Set • List • Map • .NET-specifik: • Collections.Generics • IDictionary • IList • Algoritmer: • søgning • sweep • sortering • del&hersk • rekursion • Datastrukturer: • statisk/dynamisk • array • kædet liste • træer: • søgetræer • balancerede • hashing Rasmus D. Lehrmann

  3. Collections library • Datastruktureri .NET kaldesnormaltCollections • Klasser: • Array • ArrayList • Hashtable • Stack • Queue Rasmus D. Lehrmann

  4. Collection interfaces • Collections implementer forskellige interfaces for at sikreensartethed • Klasserder implementer samme interface tilbydersamme services • gørbiblioteketlettere at læreogbruge • gørmuligt at skrivegenerisk code op mod interfacet • Interfaces: • ICollection • IEnumerable • IEnumerator • IList • IComparer • IComparable Rasmus D. Lehrmann

  5. ArrayList • ArrayList opbevare sekvenser af elementer • dataen er gemt i et array, der automatisk ændrer størrelse • bliver primært manipuleret via Ilist public class ArrayList : IList, IEnumerable, ... { // IList services ... // additional services int Capacity { get... set... } void TrimToSize() intBinarySearch(object value) intIndexOf (object value, intstartIndex) intLastIndexOf (object value, intstartIndex) ... } control of memory in underlying array searching Rasmus D. Lehrmann

  6. IList interface • IListdefinerersekvenserafelementer • kantilgås via index public interface IList : ICollection { int Add (object value); void Insert(int index, object value); void Remove (object value); void RemoveAt(int index); void Clear (); bool Contains(object value); intIndexOf (object value); object this[int index] { get; set; } boolIsReadOnly { get; } boolIsFixedSize { get; } } add new elements remove containment testing read/write existing element (see comment) structural properties Rasmus D. Lehrmann

  7. Hashtable • Hashtableunderstøtter collections af key/value pairs • keys skalværeunikke, values indeholder data • gemmerobject reference tilbåde key og value • GetHashCodemetodeaf key brugestil at bestemmeplacering Hashtable ages = new Hashtable(); ages["Ann"] = 27; ages["Bob"] = 32; ages.Add("Tom", 15); ages["Ann"] = 28; int a = (int) ages["Ann"]; create add update retrieve Rasmus D. Lehrmann

  8. Hashtabletraversering • TraverseringafHashtableindhold • hvert element er en DictionaryEntrystruktur • data gemmesiKeyogValue properties Hashtable ages = new Hashtable(); ages["Ann"] = 27; ages["Bob"] = 32; ages["Tom"] = 15; foreach (DictionaryEntry entry in ages) { string name = (string) entry.Key; int age = (int) entry.Value; ... } enumerate entries get key and value Rasmus D. Lehrmann

More Related