Friday, July 11, 2014

Printing out a linked list in reverse using recursion

Define the class for the linked list node:
class LinkedList {
public:
    int value;
    LinkedList *next;
};

populate the linked list:
void populate(int N)
{
    top = ll;
    for (int i=0 ; i< N; ++i)
    {
      ll->value = i;
      cout << ll->value;
      if( i!=N-1 ) {
        ll->next = new LinkedList;
        ll = ll->next;
     }
      else ll->next = (LinkedList *)0;
    }
    ll=top;
}

Print it out:
void print_ll()
{
    while(ll != (LinkedList *)0 ){
        cout << ll->value;
        ll = ll->next;
    }
    cout << endl;
    ll = top;
}

Reverse it:
void reverse_ll(LinkedList *node)
{
 
    if( node->next != (LinkedList *)0 ) {
        reverse_ll(node->next);
    }
    cout << node->value;
}

Please leave comments.

Thank you,
Christopher

Wednesday, January 22, 2014

Media Query parse issue

A media query running on Chrome in the following format will not work:

@media screen and (min-width:100px)and (max-width:199px){ ... }

but this will work in Chrome, Safari and FireFox:


@media screen and (min-width:100px) and (max-width:199px){ ... }

Notice the space between the closed parenthesis and 'and';  this is a parse error.  a space between these two symbols shouldn't invalidate the query.


The version of Chrome I found this in is Chrome 32.0.1700.77 Running on Mac OS X 10.9.1

If I remove the spaces then this query and have the following form:

@media screen and (min-width:100px)and(max-width:199px){ ... }

Only Safari will work.


To prevent this from happening, make sure you have spaces in your media queries.