Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Algorithms
Expertise: Beginner
Apr 22, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Adding to the front of an array

I have to read in integers and be able to add them to the front of the array. How do I do this?

You can either use the array in reverse order and simply append new items to the end of the array, or you can set the size of the array in advance and simply write items to the end of the array and work up.

If you want to insert items at the head of the array, there is no direct way to do this. You could shift everything down to make room, but this can be inefficient when the array gets large. Another approach to consider is to use a linked list instead. Items can be inserted into a linked list without shifting existing items.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date