Monday, 28 September 2009

Method to display formatted queue contents

Copy and paste the code below into your Queue class, it can then be used to display the entire Queue contents on a label.


/// <summary>
/// Retrieves a formatted String showing Queues occupancy
/// </summary>
/// <returns>A vertically formatted queue for label display</returns>
public String GetListIllustrated()
{
    String list = null;
    for (int i = 0; i < MAX; i++)
    {
        //add a newline for any other than first
        if (i > 0)
            list += "\n";
      
        //add queue position
        list += "[" + i.ToString() + "] [";
      
        //show item if it exists
        if (q[i] != null)
            list += q[i];
        else
            list += "null";
        list += "]";

        //show first and free pointers at location
        if (first == i)
            list += " <--first";
        if (free == i)
            list += " <--free";
    }
    return list;
}


No comments:

Post a Comment