Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Re: Data Structure

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Data Structure

    Hello. I'm trying to learn data structures but it is not clear for me why to use them. Why to use a different structure for example a stack instead of an array. I would appreciate it if someone could give me a simple example to understand. For example, i have a student: name, age, id... why to store these data in a differnet structure and not in an array? Thank you...


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Data Structure

    Reason Numero Uno: Arrays have a fixed size. Data structures can increase and decrease their size.

    Another reason: Arrays do not have any methods (other than those inherited from Object). Data structures have plenty of methods that can help you do what you want. Alternatively you can write your own data structure and provide whatever functionality you need. Or write a data structure that extends an existing one to enhance its capabilities.
    Improving the world one idiot at a time!

  3. #3

    Default Re: Data Structure

    Using data structures effectively is all about thinking about how a program needs to operate. Yes, arrays do have a fixed size, but you can always create another array.

    Consider this example:

    You take your set of school books and Stack them on top of your desk. This type of data structure is called first in, last out because the first book put down is the last one to get used. In order to get to the books at the bottom of the pile, you need to remove the other books from the top of the stack.
    Why is this useful?

    As a programmer you may want to limit the field of view that your data structures give it's users. The same thing goes for a Queue, first in first out. This data structure is useful when processing a list a commands that need to be executed. You would almost never do this with a Stack because there is a chance that the first command into the stack would never get executed.

    In either case, unless you are the programmer, you do not know whether the particular data structure you are using is implemented with Arrays or Linked Lists. You can always create a special class that will dynamically expand the size of its array when it gets too full by creating a new array with more space and copying the elements. Then you can simply assign the reference of the old array to the new one and voila.

    Data structures are extremely important to programmers because they provide us with a different way to think about things and allow us to solve problems differently.

    Wait until you get to Hash Tables and the use of that particular Data Structure will make itself extremely apparent.
    Kenneth Walter
    Software Developer
    http://kennywalter.com

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Data Structure

    Thank you very much, you helped me a lot. Thank you.

Similar Threads

  1. Data Structure
    By Faha in forum Object Oriented Programming
    Replies: 9
    Last Post: November 10th, 2011, 01:35 AM
  2. Replies: 2
    Last Post: June 15th, 2011, 03:49 PM
  3. Replies: 1
    Last Post: June 11th, 2011, 05:39 AM
  4. data structure assignment .. help me : |
    By Noni in forum Object Oriented Programming
    Replies: 4
    Last Post: March 21st, 2011, 10:33 AM
  5. .xls data structure
    By helloworld922 in forum JDBC & Databases
    Replies: 3
    Last Post: August 20th, 2009, 07:12 PM