Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 15. Case Study 2—An Inventory Ta... > 15.16 DELETING AN ITEM FROM THE TABL...

15.16 DELETING AN ITEM FROM THE TABLE

The code that derives from the design is given in Listing 15.8. It writes −1 to mark the deleted item.

Listing 15.8.

public static void deleteItem() throws IOException {
       int key, location;
       System.out.print("Key value to delete: ");

       key = readValue();
       location = key % 20;
       int count = 0;
       while (code[location] != key && count < 20) {
         count++;
       if (location == 19)
           location = 0;
       else
           location++;
        }
      if (count == 20)
          System.out.println("No such key value present");
      else {
          code[location] = −1;
          name[location] = " ";
           instock[location] = 0;
           System.out.println("Key  marked as deleted");
         }
       }


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint