Friday, July 5, 2013

Arrays and Indexers in VB.NET



Today's post is about Arrays and Indexers in VB.NET. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know "all" about them, in fact, it is more to show you how you do that in VB.NET, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.

By the way, if you missed my most recent post, "New Series - Arrays and Indexers", check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous post about arrays in C# (or the next one in Oxygene) just to compare.

I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.

Last thing. There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own "series" of posts.

Namespace VbArrays

    Module Program

        Sub Main()

            ' Single-dimensional Array(s)  
            PrintTitle("Reverse Array Elements")

            ' Declare and Initialize Array of Chars  
            ' You must specify the maximum index instead of the Length.
            Dim letters(4) As Char
            letters(0) = "A"
            letters(1) = "E"
            letters(2) = "I"
            letters(3) = "O"
            letters(4) = "U"

            PrintArrayChar(letters)
            Dim inverse_letters() As Char = ReverseChar(letters)
            PrintArrayChar(inverse_letters)

            PrintTitle("Sort Integer Array Elements")

            Dim numbers() As Integer = {10, 8, 3, 1, 5}
            PrintArrayInt(numbers)
            Dim ordered_numbers() As Integer = BubbleSortInt(numbers)
            PrintArrayInt(ordered_numbers)

            PrintTitle("Sort String Array Elements")

            ' Declare and Initialize and Array of Strings  
            Dim names() As String = New String() {
                    "Damian",
                    "Rogelio",
                    "Carlos",
                    "Luis",
                    "Daniel"
                }
            PrintArrayString(names)
            Dim ordered_names() As String = BubbleSortString(names)
            PrintArrayString(ordered_names)

            ' Multi-dimensional Array (Matrix row,column)  

            PrintTitle("Transpose Matrix")

            ' Matrix row=2,col=3 
            ' A =  [6  4 24] 
            '      [1 -9  8] 
            '
            Dim matrix(,) As Integer = New Integer(1, 2) {{6, 4, 24},
                                                          {1, -9, 8}}
            PrintMatrix(matrix)
            Dim transposed_matrix(,) As Integer = TransposeMatrix(matrix)
            PrintMatrix(transposed_matrix)

            ' Jagged Array (Array-of-Arrays)  

            PrintTitle("Upper Case Random Array & Graph Number of Elements")

            '              
            ' Creating an array of string arrays using the String.Split method 
            ' instead of initializing it manually as follows: 
            '  
            ' Dim text As String()() = New String()() {  
            '      New String() { "word1", "word2", "wordN" },  
            '      New String() { "word1", "word2", "wordM" },  
            '      ... 
            '      } 
            '  
            ' Text extract from: "El ingenioso hidalgo don Quijote de la Mancha" 
            '  
            '  
            Dim text As String()() = {
            "Hoy es el día más hermoso de nuestra vida, querido Sancho;".Split(" "),
            "los obstáculos más grandes, nuestras propias indecisiones;".Split(" "),
            "nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;".Split(" "),
            "la cosa más fácil, equivocarnos;".Split(" "),
            "la más destructiva, la mentira y el egoísmo;".Split(" "),
            "la peor derrota, el desaliento;".Split(" "),
            "los defectos más peligrosos, la soberbia y el rencor;".Split(" "),
            "las sensaciones más gratas, la buena conciencia...".Split(" ")
            }
            PrintJaggedArray(text)
            UpperCaseRandomArray(text)
            PrintJaggedArray(text)
            GraphJaggedArray(text)

            ' Array Exceptions  

            PrintTitle("Common Array Exceptions")

            PrintCommonArrayExceptions(Nothing)
            PrintCommonArrayExceptions(text)

            ' Accessing Class Array Elements through Indexer  

            PrintTitle("Alphabets")

            Dim vowels As Alphabet = New Alphabet(4)
            vowels(0) = "a"
            vowels(1) = "e"
            vowels(2) = "i"
            vowels(3) = "o"
            vowels(4) = "u"

            Console.WriteLine(ControlChars.CrLf & "Vowels = {{{0}}}",
                String.Join(",", vowels(0), vowels(1), vowels(2), vowels(3), vowels(4)))

            Dim en As New Alphabet("abcdefghijklmnopqrstuvwxyz")
            Console.WriteLine("English Alphabet = {{{0}}}", en.ToString())

            Console.WriteLine("Alphabet Extract en[9..19] = {{{0}}}",
                          New Alphabet(en.Slice(9, 10)))

            Dim word1 As String = String.Join("", en(6), en(14), en(14), en(3))
            Dim word2 As String = String.Join("", en(1), en(24), en(4))
            Dim word3 As String = String.Join("", en(4), en(21), en(4), en(17),
                                           en(24), en(14), en(13), en(4))

            Console.WriteLine(ControlChars.CrLf & "{0} {1}, {2}!" &
                               ControlChars.CrLf, word1, word2, word3)

        End Sub

        Function ReverseChar(ByVal arr() As Char) As Char()
            Dim reversed(arr.Length - 1) As Char
            Dim i As Integer = 0
            For j As Integer = arr.Length - 1 To 0 Step -1
                reversed(i) = arr(j)
                i += 1
            Next
            Return reversed
        End Function

        Function BubbleSortInt(ByVal arr() As Integer) As Integer()
            Dim swap As Integer = 0
            For i As Integer = arr.Length - 1 To 0 Step -1
                For j As Integer = 0 To i - 1
                    If arr(j) > arr(j + 1) Then
                        swap = arr(j)
                        arr(j) = arr(j + 1)
                        arr(j + 1) = swap
                    End If
                Next j
            Next i
            Return arr
        End Function

        Function BubbleSortString(ByVal arr() As String) As String()
            Dim swap As String = ""
            For i As Integer = arr.Length - 1 To 0 Step -1
                For j As Integer = 0 To i - 1
                    If arr(j)(0) > arr(j + 1)(0) Then
                        swap = arr(j)
                        arr(j) = arr(j + 1)
                        arr(j + 1) = swap
                    End If
                Next j
            Next i
            Return arr
        End Function

        Function TransposeMatrix(ByVal m(,) As Integer) As Integer(,)
            ' Transposing a Matrix 2,3  
            '  
            ' A =  [6  4 24]T [ 6  1]  
            '      [1 -9  8]  [ 4 -9] 
            '                 [24  8] 
            '
            Dim transposed(m.GetUpperBound(1), m.GetUpperBound(0)) As Integer
            For i As Integer = 0 To m.GetUpperBound(0)
                For j As Integer = 0 To m.GetUpperBound(1)
                    transposed(j, i) = m(i, j)
                Next
            Next
            Return transposed
        End Function

        Sub UpperCaseRandomArray(ByRef arr As String()())
            Dim r As Random = New Random
            Dim i As Integer = r.Next(0, arr.Length - 1)
            For j As Integer = 0 To arr(i).Length - 1
                arr(i)(j) = arr(i)(j).ToUpper
            Next
        End Sub

        Sub PrintArrayChar(ByVal arr() As Char)
            Console.WriteLine(ControlChars.CrLf & "Print Array Content {0}",
               arr.GetType().Name.Replace("]", arr.Length.ToString + "]"))

            For i As Integer = 0 To arr.Length - 1
                Console.WriteLine(" array [{0,2}] = {1,2} ", i, arr(i))
            Next
        End Sub

        Sub PrintArrayInt(ByVal arr() As Integer)
            Console.WriteLine(ControlChars.CrLf & "Print Array Content {0}",
               arr.GetType.Name.Replace("]", arr.Length.ToString + "]"))

            For i As Integer = 0 To arr.Length - 1
                Console.WriteLine(" array [{0,2}] = {1,2} ", i, arr(i))
            Next
        End Sub

        Sub PrintArrayString(ByVal arr() As String)
            Console.WriteLine(ControlChars.CrLf & "Print Array Content {0}",
               arr.GetType.Name.Replace("]", arr.Length.ToString + "]"))

            For i As Integer = 0 To arr.Length - 1
                Console.WriteLine(" array [{0,2}] = {1,2} ", i, arr(i))
            Next
        End Sub

        Sub PrintMatrix(ByVal m As Integer(,))
            Console.WriteLine(ControlChars.CrLf & "Print Matrix Content {0}[{1},{2}]",
                m.GetType.Name.Replace("[,]", ""),
                (m.GetUpperBound(0) + 1).ToString,
                (m.GetUpperBound(1) + 1).ToString)

            For i As Integer = 0 To m.GetUpperBound(0)
                For j As Integer = 0 To m.GetUpperBound(1)
                    Console.WriteLine(" array [{0,2},{1,2}] = {2,2} ", i, j, m(i, j))
                Next
            Next
        End Sub

        Sub GraphJaggedArray(ByVal arr()() As String)
            ' When using Arrays, we can use foreach instead of for:  
            '  
            ' For i As Integer = 0 To arr.Length
            '   For j As Integer = 0 To arr.Length
            '  
            '
            Console.WriteLine(ControlChars.CrLf & "Print Text Content {0}",
                              arr.GetType.Name)
            Dim lineCount As Integer = 1
            For Each s In arr
                Console.Write("Line{0,2}|", lineCount)
                For Each w In s
                    Console.Write("{0,3}", "*")
                Next
                Console.WriteLine(" ({0})", s.Length)
                lineCount += 1
            Next
        End Sub

        Sub PrintJaggedArray(ByVal arr()() As String)
            Dim line As System.Text.StringBuilder
            Console.WriteLine(ControlChars.CrLf & "Print Jagged Array Content {0}",
                              arr.GetType.Name)
            For i As Integer = 0 To arr.Length - 1
                line = New System.Text.StringBuilder
                For j As Integer = 0 To arr(i).Length - 1
                    line.Append(" " + arr(i)(j))
                Next
                If line.ToString = line.ToString.ToUpper Then
                    line.Append(" <-- [UPPERCASED]")
                End If
                Console.WriteLine(line)
            Next
        End Sub

        Sub PrintCommonArrayExceptions(ByVal arr()() As String)
            Try
                arr(100)(100) = "hola"
            Catch ex As Exception
                Console.WriteLine(ControlChars.CrLf & "Exception: " &
                                  ControlChars.CrLf & "{0}" &
                                  ControlChars.CrLf & "{1}", ex.GetType.Name, ex.Message)
            End Try
        End Sub

        Sub PrintTitle(ByVal message As String)
            Console.WriteLine()
            Console.WriteLine("======================================================")
            Console.WriteLine("{0,10}", message)
            Console.WriteLine("======================================================")
        End Sub

    End Module

    Class Alphabet
        ' Array Field
        Private letters() As Char

        ' Indexer Get/Set Property 
        Default Public Property Item(ByVal index As Integer) As Char
            Get
                Return letters(index)
            End Get
            Set(value As Char)
                letters(index) = Char.ToUpper(value)
            End Set
        End Property

        ' Read-Only Property 
        Public ReadOnly Property Length() As Integer
            Get
                Return Me.letters.Length
            End Get
        End Property

        ' Constructors
        Public Sub New(ByVal size As Integer)
            Me.letters = New Char(size) {}
        End Sub

        Public Sub New(ByVal list As String)
            Me.letters = list.ToUpper.ToCharArray
        End Sub

        Public Sub New(ByVal list() As Char)
            Me.letters = list
        End Sub

        ' Overridden Method 
        Public Overrides Function ToString() As String
            Return String.Join(",", letters)
        End Function

        ' Method
        Public Function Slice(ByVal start As Integer, ByVal length As Integer) As Char()
            Dim result(length) As Char
            Dim j As Integer = start
            For i As Integer = 0 To length
                result(i) = Me(j)
                j += 1
            Next
            Return result
        End Function

    End Class

End Namespace


The output:






















































































Voilà, that's it. Next post in the following days.

Monday, July 1, 2013

Arrays and Indexers in C#



Today's post is about Arrays and Indexers in C#. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know "all" about them, in fact, it is more to show you how you do that in C#, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.

By the way, if you missed my most recent post, "New Series - Arrays and Indexers", check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts.

Ok, enough talk, let's see C# version of the code.
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.

Last thing. There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own "series" of posts.

using System;

namespace CsArrays
{
    class Program
    {
        static void Main(string[] args)
        {
            // Single-dimensional Array(s)
            PrintTitle("Reverse Array Elements");

            // Declare and Initialize Array of Chars
            char[] letters = new char[5];
            letters[0] = 'A';
            letters[1] = 'E';
            letters[2] = 'I';
            letters[3] = 'O';
            letters[4] = 'U';

            PrintArrayChar(letters);
            char[] inverse_letters = ReverseChar(letters);
            PrintArrayChar(inverse_letters);

            PrintTitle("Sort Integer Array Elements");

            // Declare and Initialize Array of Integers 
            int[] numbers = { 10, 8, 3, 1, 5 };
            PrintArrayInt(numbers);
            int[] ordered_numbers = BubbleSortInt(numbers);
            PrintArrayInt(ordered_numbers);

            PrintTitle("Sort String Array Elements");

            // Declare and Initialize and Array of Strings
            string[] names = new string[] {                     
                    "Damian", 
                    "Rogelio",
                    "Carlos", 
                    "Luis",                     
                    "Daniel"
                };
            PrintArrayString(names);
            string[] ordered_names = BubbleSortString(names);
            PrintArrayString(ordered_names);

            // Multi-dimensional Array (Matrix row,column)

            PrintTitle("Transpose Matrix");

            /* Matrix row=2,col=3
             * A =  [6  4 24]
             *      [1 -9  8]
            */
            int[,] matrix = new int[2, 3] { { 6, 4, 24 }, 
                                            { 1, -9, 8 } };
            PrintMatrix(matrix);
            int[,] transposed_matrix = TransposeMatrix(matrix);
            PrintMatrix(transposed_matrix);

            // Jagged Array (Array-of-Arrays)

            PrintTitle("Upper Case Random Array & Graph Number of Elements");

            /*             
             * Creating an array of string arrays using the String.Split method
             * instead of initializing it manually as follows:
             * 
             * string[][] text = new string[][] { 
             *      new string[] { "word1", "word2", "wordN" }, 
             *      new string[] { "word1", "word2", "wordM" }, 
             *      ...
             *      };
             * 
             * Text extract from: "El ingenioso hidalgo don Quijote de la Mancha"
             * 
             */
            string[][] text = { 
            "Hoy es el día más hermoso de nuestra vida, querido Sancho;".Split(' '),
            "los obstáculos más grandes, nuestras propias indecisiones;".Split(' '),
            "nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;".Split(' '),
            "la cosa más fácil, equivocarnos;".Split(' '),
            "la más destructiva, la mentira y el egoísmo;".Split(' '),
            "la peor derrota, el desaliento;".Split(' '),
            "los defectos más peligrosos, la soberbia y el rencor;".Split(' '),
            "las sensaciones más gratas, la buena conciencia...".Split(' ') 
            };
            PrintJaggedArray(text);
            UpperCaseRandomArray(text);
            PrintJaggedArray(text);
            GraphJaggedArray(text);

            // Array Exceptions

            PrintTitle("Common Array Exceptions");

            PrintCommonArrayExceptions(null);
            PrintCommonArrayExceptions(text);

            // Accessing Class Array Elements through Indexer

            PrintTitle("Alphabets");

            Alphabet vowels = new Alphabet(5);
            vowels[0] = 'a';
            vowels[1] = 'e';
            vowels[2] = 'i';
            vowels[3] = 'o';
            vowels[4] = 'u';

            Console.WriteLine("\nVowels = {{{0}}}",
                String.Join(",", vowels[0], vowels[1], vowels[2], vowels[3], vowels[4]));

            Alphabet en = new Alphabet("abcdefghijklmnopqrstuvwxyz");
            Console.WriteLine("English Alphabet = {{{0}}}", en.ToString());

            Console.WriteLine("Alphabet Extract en[9..19] = {{{0}}}", 
                          new Alphabet(en.Slice(9, 10)));

            string word1 = String.Join("", en[6], en[14], en[14], en[3]);
            string word2 = String.Join("", en[1], en[24], en[4]);
            string word3 = String.Join("", en[4], en[21], en[4], en[17],
                                           en[24], en[14], en[13], en[4]);

            Console.WriteLine("\n{0} {1}, {2}!\n", word1, word2, word3);

        }

        static char[] ReverseChar(char[] arr)
        {
            char[] reversed = new char[arr.Length];
            for (int i = 0, j = arr.Length - 1; j >= 0; i++, j--)
                reversed[i] = arr[j];
            return reversed;
        }

        static int[] BubbleSortInt(int[] arr)
        {
            int swap = 0;
            for (int i = arr.Length - 1; i > 0; i--)
            {
                for (int j = 0; j < i; j++)
                {
                    if (arr[j] > arr[j + 1])
                    {
                        swap = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = swap;
                    }
                }
            }
            return arr;
        }

        static string[] BubbleSortString(string[] arr)
        {
            string swap = "";
            for (int i = arr.Length - 1; i > 0; i--)
            {
                for (int j = 0; j < i; j++)
                {
                    if (arr[j][0] > arr[j + 1][0])
                    {
                        swap = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = swap;
                    }
                }
            }
            return arr;
        }

        static int[,] TransposeMatrix(int[,] m)
        {
            /* Transposing a Matrix 2,3 
             * 
             * A =  [6  4 24]T [ 6  1] 
             *      [1 -9  8]  [ 4 -9]
             *                 [24  8]
            */
            int[,] transposed = new int[m.GetUpperBound(1) + 1,
                                        m.GetUpperBound(0) + 1];
            for (int i = 0; i < m.GetUpperBound(0) + 1; i++)
            {
                for (int j = 0; j < m.GetUpperBound(1) + 1; j++)
                {
                    transposed[j, i] = m[i, j];
                }
            }
            return transposed;
        }

        static void UpperCaseRandomArray(string[][] arr)
        {
            Random r = new Random();
            int i = r.Next(0, arr.Length - 1);
            for (int j = 0; j <= arr[i].Length - 1; j++)
                arr[i][j] = arr[i][j].ToUpper();
        }

        static void PrintArrayChar(char[] arr)
        {
            Console.WriteLine("\nPrint Array Content {0}",
                arr.GetType().Name.Replace("]", arr.Length.ToString() + "]"));

            for (int i = 0; i <= arr.Length - 1; i++)
                Console.WriteLine(" array [{0,2}] = {1,2} ", i, arr[i]);
        }

        static void PrintArrayInt(int[] arr)
        {
            Console.WriteLine("\nPrint Array Content {0}",
                arr.GetType().Name.Replace("]", arr.Length.ToString() + "]"));

            for (int i = 0; i <= arr.Length - 1; i++)
                Console.WriteLine(" array [{0,2}] = {1,2} ", i, arr[i]);
        }

        static void PrintArrayString(string[] arr)
        {
            Console.WriteLine("\nPrint Array Content {0}",
                arr.GetType().Name.Replace("]", arr.Length.ToString() + "]"));

            for (int i = 0; i <= arr.Length - 1; i++)
                Console.WriteLine(" array [{0,2}] = {1,2} ", i, arr[i]);
        }

        static void PrintMatrix(int[,] m)
        {
            Console.WriteLine("\nPrint Matrix Content {0}[{1},{2}]",
                m.GetType().Name.Replace("[,]", ""),
                (m.GetUpperBound(0) + 1).ToString(),
                (m.GetUpperBound(1) + 1).ToString());

            for (int i = 0; i <= m.GetUpperBound(0); i++)
                for (int j = 0; j <= m.GetUpperBound(1); j++)
                    Console.WriteLine(" array [{0,2},{1,2}] = {2,2} ", i, j, m[i, j]);
        }

        static void GraphJaggedArray(string[][] arr)
        {
            /* When using Arrays, we can use foreach instead of for: 
             * 
             * for (int i = 0; i <= arr.Length - 1; i++)
             *   for (int j = 0; j <= arr.Length - 1; j++)                
             * 
            */
            Console.WriteLine("\nPrint Text Content {0}", arr.GetType().Name);
            int lineCount = 1;
            foreach (string[] s in arr)
            {
                Console.Write("Line{0,2}|", lineCount);
                foreach (string w in s)
                {
                    Console.Write("{0,3}", '*');
                }
                Console.WriteLine(" ({0})", s.Length);
                lineCount++;
            }
        }

        static void PrintJaggedArray(string[][] arr)
        {
            System.Text.StringBuilder line;
            Console.WriteLine("\nPrint Jagged Array Content {0}", arr.GetType().Name);
            for (int i = 0; i <= arr.Length - 1; i++)
            {
                line = new System.Text.StringBuilder();
                for (int j = 0; j <= arr[i].Length - 1; j++)
                    line.Append(" " + arr[i][j]);
                if (line.ToString() == line.ToString().ToUpper())
                    line.Append(" <-- [UPPERCASED]");
                Console.WriteLine(line);
            }
        }

        static void PrintCommonArrayExceptions(string[][] arr)
        {
            try
            {
                arr[100][100] = "hola";
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nException: \n{0}\n{1}", ex.GetType().Name, ex.Message);
            }
        }

        static void PrintTitle(string message)
        {
            Console.WriteLine();
            Console.WriteLine("======================================================");
            Console.WriteLine("{0,10}", message);
            Console.WriteLine("======================================================");
        }

    }

    class Alphabet
    {
        // Array Field
        private char[] letters;

        // Indexer Get/Set Property 
        public char this[int index]
        {
            get { return letters[index]; }
            set { letters[index] = Char.ToUpper(value); }
        }

        // Read-Only Property
        public int Length
        {
            get { return this.letters.Length; }
        }

        // Constructors
        public Alphabet(int size)
        {
            this.letters = new char[size];
        }

        public Alphabet(string list)
        {
            this.letters = list.ToUpper().ToCharArray();
        }

        public Alphabet(char[] list)
        {
            this.letters = list;
        }

        // Overridden Method
        public override string ToString()
        {
            return String.Join(",", this.letters);
        }

        // Method
        public char[] Slice(int start, int length)
        {
            char[] result = new char[length];
            for (int i = 0, j = start; i < length; i++, j++)
            {
                result[i] = this[j];
            }
            return result;
        }

    }
}


The output:






















































































Voilà, that's it. Next post in the following days.

Friday, June 28, 2013

New Series - Arrays and Indexers



Today, I'm going to start a new series of posts called "Arrays and Indexers in [Programming Language]".  As with previous posts, my aim is to show programming language's basic features, in this case, Arrays and Indexers.

There will a little program. It will show the different declaration and initialization syntax for single-dimensional, multi-dimensional and jagged (arrays of arrays) arrays, how to access elements using numerical index, how to use them as method's input parameters and return type. For the last example, I will define a class that implements the Indexer with its respective get set properties/methods and use it.

Regarding the demonstrating code, I chose an easy array-based sorting algorithm "BubbleSort" (single-dimensional array), a Matrix Transpose (multi-dimensional array) and a Random Uppercase Array. There will also be some Print Array Content methods to display the elements of the array. For the indexer part, it will just encapsulate an array of characters to store alphabets and access specific letters on it.

Each post of the series will be implemented in the latest version, available at the time of writing (stable or unstable), of the following languages targeting the latest version of the supported stable Runtime (JDK7 & .NET4.5)

CLR: C#, VB.NET, C++/CLI, F#, Boo, Phalanger, IronPython, IronRuby, Oxygene, Zonnon, Nemerle, Cobra, JScript.NET.

JVM: Java, Groovy, Jython, JRuby, Fantom, Scala, Gosu, Ceylon, Xtend, Kotlin.

And will use its respective System.Array or java.util.Array.


The Program's Structure will be (more or less) as follows:
// imports 
// namespace 
    
    // Program Class
    
        // Main Mathod            
            
            // Single-dimensional Array(s)            
            
            // Declare & Initialize Character Array
            // Reverse Array Elements
            // Print Array 
            
            // Declare & Initialize Integer Array
            // Sort Integer Array Elements
            // Print Array 
            
            // Declare & Initialize String Array
            // Sort String Array Elements
            // Print Array 
            
            // Multi-dimensional Array (Matrix row,column)
                        
            // Declare & Initialize Matrix Array
            // Transpose Matrix
            // Print Array
            
            // Jagged Array (array of array)
            
            // Upper Case Random Array 
            // Print Array
            // Graph Number of Elements
            
            // Common Array Exceptions
            
            // Print Exceptions
            
            // Indexers Usage
            
            // Declare & Initialize
            // Access Class Array Elements via Indexer
        
        // Method: ReverseChar          - Char[] 
        // Method: BubbleSortInt        - Integer[] 
        // Method: BubbleSortString     - String[] 
        // Method: TransposeMatrix      - Integer[,] 
        // Method: UpperCaseRandomArray - String[][] 
        // Method: PrintArrayChar       - Char[] 
        // Method: PrintArrayInt        - Integer[] 
        // Method: PrintArrayString     - String[] 
        // Method: PrintMatrix          - Integer[,]
        // Method: GraphJaggedArray     - String[][]
        // Method: PrintJaggedArray     - String[][]
        // Method: PrintCommonArrayExceptions - String[][]
        // Method: PrintTitle            
        
    // Indexer Class
        
        // Field: Char Array        
        // Indexer
            // Get
            // Set
        // Constructor: - Integer
        // Constructor: - String
        // Constructor: - Char Array
        // Method: toString
        // Method: Slice
        



Here below some definitions of the new concepts:

Array
"An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched."
Taken from: http://www.techterms.com/definition/array

One-dimensional arrays
"A one-dimensional array (or single dimension array) is a type of linear array. Accessing its elements involves a single subscript which can either represent a row or column index."
Taken from: http://en.wikipedia.org/wiki/One-dimensional_array#One-dimensional_arrays

Multidimensional arrays
"A data structure consisting of a vector of vectors, in the case of a 2-dimensional array, or, in the case of an N-dimensional array, a vector of multidimensional arrays of degree N minus 1, thereby allowing the simulation of a N-dimensional grid of storage locations using an underlying memory architecture in which storage is addressed in a linear fashion."
Taken from: http://en.wiktionary.org/wiki/multidimensional_array

Jagged Arrays
"In computer programming, an Iliffe vector (Jagged Arrays or Array of Arrays), also known as a display, is a data structure used to implement multi-dimensional arrays. An Iliffe vector for an n-dimensional array (where n > 2) consists of a vector (or 1-dimensional array) of pointers to an (n - 1)-dimensional array. They are often used to avoid the need for expensive multiplication operations when performing address calculation on an array element."
Taken from: http://en.wikipedia.org/wiki/Jagged_array

Bubble Sort Algorithm
"Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted."
Sorting Algorithm in Action: http://www.sorting-algorithms.com/bubble-sort
Taken from: http://en.wikipedia.org/wiki/Bubblesort

Matrix
"In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns.[1][2] The individual items in a matrix are called its elements or entries. An example of a matrix with 2 rows and 3 columns is: "





Taken from: http://en.wikipedia.org/wiki/Matrix_(mathematics)

Matrix Transpose
"A matrix which is formed by turning all the rows of a given matrix into columns and vice-versa. The transpose of matrix A is written AT."
1 image says more than N words









Taken from: http://www.mathwords.com/t/transpose_of_a_matrix.htm

Indexer
"In object-oriented programming, an indexer allows instances of a particular class or struct to be indexed just like arrays"
"Indexers are implemented through the not get and set accessors for the operator[]. They are similar to properties, but differ by not being static, and the fact that indexers' accessors take parameters."
Taken from: http://en.wikipedia.org/wiki/Indexer_(programming)

Array Slicing
"In computer programming, array slicing is an operation that extracts certain elements from an array and packages them as another array, possibly with different number of indices (or dimensions) and different index ranges."
Taken from: http://en.wikipedia.org/wiki/Array_slicing




Tuesday, June 25, 2013

And, What Next?


It's been a while since my last post... worry not, this blog is neither dead nor forgotten, in fact, the Languages page is constantly being updated to reflect latest releases. Besides that, I often log in to see who has visited this blog and pretty much all the other stuff that the good Google Analytics has to tell me. For instance, here is the info of the last 30 days (May 25, 2013-Jun 24, 2013):

Visitors Location :


Numbers of Visits and Top 10 avg time:



Not bad! 1 - 2 minutes is not bad at all I think, even though there lots of visits with 0:00 lol. Anyway, let's see if I get more audience now that I plan to continue writing some posts. In fact I will start a new series about another very useful feature which almost every programming language supports: "Arrays". In this series I will write a couple of little programs demonstrating the syntax to declare, initialize and access elements through its index. I will also include an example of Indexers usage to make your own class accessible via numeric index, just like you do with arrays.

Other topics I was thinking about were Operator Overloading, Inheritance and Generics, but I think Arrays is far more basic than those.

Bon voilà, c'est tout. Au revoir!