what is difference between Array and list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swarnkar48
    New Member
    • Apr 2010
    • 1

    #1

    what is difference between Array and list

    what is difference between Array and list?
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    The main difference between an array and a list is how they internally store the data. In an array the data is stored sequentially in memory.

    So if you have an array of integers.

    int array[10];

    In memory each element (array[0] to array[9]) is stored one after another.

    For a list this isn't true. A list contains a pointer to the next element and potentially the previous element for a doubly linked list. The first element in a list is usually refered to as the head and the last element is refered as the tail.

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      Yes and the beauty of a list is that you can insert an element anywhere within it whereas in an array you have to move a flock of elements to make room for the new one. A list does not have to be stored in memory sequentially (as in an array) because each node has the address of the next one.

      Comment

      • manavshah
        New Member
        • Apr 2012
        • 1

        #4
        A linked list can grow and shrink dynamically as you can add and delete nodes. However, array can not as it is static data structure.

        Comment

        Working...