array vs list.

Discussion in 'C++' started by pkbis28, May 28, 2010.

  1. pkbis28

    pkbis28 New Member

    Joined:
    May 25, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    What is the difference between an ARRAY and a LIST?
     
  2. singh_r85

    singh_r85 New Member

    Joined:
    May 25, 2010
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    Array uses direct access of stored members, list uses sequencial access for members.

    //With Array you have direct access to memory position 5
    Object x = a[5]; // x takes directly a reference to 5th element of array

    //With the list you have to cross all previous nodes in order to get the 5th node:
    list mylist;
    list::iterator it;

    for( it = list.begin() ; it != list.end() ; it++ )
    {
    if( i==5)
    {
    x = *it;
    break;
    }
    i++;
    }
     
  3. spoddar66

    spoddar66 New Member

    Joined:
    May 25, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    i am giving a comparative idea apart from singh_r85 post


    Array is collection of homogeneous elements.
    List is collection of heterogeneous elements.

    For Array memory allocated is static and continuous.
    For List memory allocated is dynamic and Random.

    Array: User need not have to keep in track of next memory allocation.
    List: User has to keep in Track of next location where memory is allocated.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice