Created
March 8, 2014 12:15
-
-
Save d8ta/9429606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 1310601027, fhs36118 | |
| * Daniel Raudschus | |
| * ue02 bsp08 | |
| * */ | |
| //8. MyIntArray (2P): | |
| //Programmiere eine eigene, auf integer-Werte reduzierte Version einer ArrayList namens MyIntArray. | |
| //Dieses Array kapselt ein Standard-Integer-Array (int[] numbers), und darf NICHT eineArrayListverwenden. | |
| //Es muss das dynamische Wachsen des Arrays unterstützen. | |
| //Die Klasse muss Folgendes beinhalten/leisten (2P): | |
| //(a) standardmäßig eine Kapaziät von 16 Elementen besitzen | |
| //(b) einen Konstruktor besitzen, der eine andere Startkapazität erlaubt | |
| //(c) bei Add(int value) ein Element hinten anhängen, und gegebenfalls das gekapselte Array verdoppeln | |
| //(d) Count(AnzahldergespeichertenElemente)und Capacity(tatsächliche Grö̈ße des Arrays) zurückliefern | |
| //(e) bool Contains(int value): ermittelt, ob das Element value im Array vorhanden ist | |
| //(f) void Reverse(): die Reihenfolge des Arrays umdrehen. | |
| //(g) void Print(): zur Ausgabe des Arrays in der Konsole. | |
| using System; | |
| using System.Diagnostics; | |
| class IntArrayList | |
| { | |
| protected static int size; | |
| protected static int[] numbers = new int[size]; | |
| protected static int[] MyIntArray = numbers; | |
| // (a) standardmäßig eine Kapaziät von 16 Elementen besitzen | |
| public IntArrayList() | |
| { | |
| size = 15; | |
| } | |
| // (b) einen Konstruktor besitzen, der eine andere Startkapazität erlaubt | |
| public IntArrayList(int size) | |
| { | |
| size = size; | |
| } | |
| // (c) bei Add(int value) ein Element hinten anhängen, und gegebenfalls das gekapselte Array verdoppeln | |
| public void Add(int value) | |
| { | |
| } | |
| // // (d) Count(AnzahldergespeichertenElemente) | |
| // public int Count() | |
| // { | |
| // | |
| // } | |
| // | |
| // // Capacity(tatsächliche Grö̈ße des Arrays) zurückliefern | |
| // public int Capacity() | |
| // { | |
| // | |
| // } | |
| // | |
| // // (e) bool Contains(int value): ermittelt, ob das Element value im Array vorhanden ist | |
| // public bool Contains(int value) | |
| // { | |
| // | |
| // } | |
| // (f) void Reverse(): die Reihenfolge des Arrays umdrehen | |
| public void Revers() | |
| { | |
| } | |
| // (g) void Print(): zur Ausgabe des Arrays in der Konsole | |
| public void Print() | |
| { | |
| for (int i = 0; i < MyIntArray.Length; i++) { | |
| Console.WriteLine (MyIntArray[i]); | |
| } | |
| } | |
| } | |
| class MainClass | |
| { | |
| public static void Main (string[] args) | |
| { | |
| IntArrayList list = new IntArrayList (20); | |
| list.Print (); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment