Elements of the enumerated array are numbers

Saturday, August 1st, 2009

 <?php
  $sortnumbers []= 10000;
  $sortnumbers []= 10;
  $sortnumbers []= 100;
  $sortnumbers []= 1000;
  $sortnumbers []= 1;

  sort ($sortnumbers);

  foreach ($sortnumbers as $val) {
    echo "$val", "\n";
  }
 ?>

           
       

Use the greater function object in Map

Sunday, July 26th, 2009

#include <iostream>
#include <map>
#include <functional>
#include <string>
using namespace std;

int main()
{
  map<string, int, greater<string> > mapObject;

  mapObject["A"] = 20;
  mapObject["B"] = 19;
  mapObject["C"] = 10;

  map<string, int, greater<string> >::iterator p;
  
  for(p = mapObject.begin(); p != mapObject.end(); p++) {
    cout << p->first << " has value of ";
    cout << p->second << endl;
  }

  return 0;
}

           
       

Sort an Array and Use Array.Length properties

Thursday, July 16th, 2009

Imports System

Public Class MainClass

    Shared Sub Main(ByVal args As String())
        Dim friends(4) As String

        friends(0) = "1"
        friends(1) = "2"
        friends(2) = "3"
        friends(3) = "4"
        friends(4) = "5"

        Array.Sort(friends)

        Dim upperBound As Integer = friends.Length - 1

        Dim index As Integer
        For index = upperBound To 0 Step -1

            Console.WriteLine(friends(index))

        Next

    End Sub
    

End Class

           
       

Stack to Array

Tuesday, July 7th, 2009

Imports System
Imports System.Collections

Public Class MainClass
    
    Shared Sub Main()
             Dim intStack As New Stack(  )

             Dim i As Integer
             For i = 1 To 4
                 intStack.Push((i * 5))
             Next i

             Console.WriteLine("intStack values:")
             DisplayValues(intStack)

             Const arraySize As Integer = 10
             Dim testArray(arraySize) As Integer

             For i = 1 To arraySize - 1
                 testArray(i) = i * 100
             Next i
             Console.WriteLine("Contents of the test array")
             DisplayValues(testArray)

             intStack.CopyTo(testArray, 3)
             Console.WriteLine("TestArray after copy:  ")
             DisplayValues(testArray)

             Dim myArray As Object(  ) = intStack.ToArray(  )

             Console.WriteLine("The new array:")
             DisplayValues(myArray)
   End Sub

   Public Shared Sub DisplayValues(ByVal myCollection As IEnumerable)
       Dim myEnumerator As IEnumerator = myCollection.GetEnumerator(  )
       While myEnumerator.MoveNext(  )
           Console.WriteLine("{0} ", myEnumerator.Current)
       End While
       Console.WriteLine(  )
   End Sub

End Class

           
       

key: Fetch a key from an associative array

Sunday, June 28th, 2009

<?php
   $capitals = array("Ohio" => "Columbus", "Iowa" => "Des Moines","Arizona" => "Phoenix");
   echo "<p>Can you name the capitals of these states?</p>";
   while($key = key($capitals)) {
      echo $key."<br />";
      next($capitals);
   }
?>