Problem Solving with Algorithms

반응형

Inserting Items Into an Array

In the previous chapter, we looked at what Arrays are, and the basic programming constructs of Arrays in Java. We're now going to use these basic constructs to implement three key operations for Arrays:

  • Inserting items.
  • Removing items.
  • Searching for items.

These three operations are the fundamental operations for all data structures.

In this chapter, we'll be starting with inserting items into an array. Like before, we'll approach the learning with lots of examples and programming snippets. After that, there are some more interview questions for you to practice on. We hope you have fun!


 

Basic Array Operations

Now that we have a fairly good understanding of what an Array actually is, and how it is stored inside the computer's physical memory, the next important thing to look at is all the operations that Arrays support. An Array is a data structure, which means that it stores data in a specific format and supports certain operations on the data it stores. Consider the DVD inventory management software from the introduction section. Let's look at some operations you might want to perform using this software:

  • Insert a new DVD into the collection at a specific location.
  • Delete a DVD from the existing collection if it doesn't make sense to keep it in the inventory anymore.
  • Search for a particular DVD in the collection. This is one of the most commonly executed operation on our collection, because our inventory management software would be used hundreds of times a day to look for a particular DVD asked for by the user.

In this section, we'll be looking at the three basic operations that are supported by almost every data structure; insertion, deletion, and search.

 


 

반응형
반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band