{"id":375,"date":"2012-08-16T22:32:12","date_gmt":"2012-08-17T05:32:12","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/infs1609\/?p=375"},"modified":"2012-08-26T21:04:22","modified_gmt":"2012-08-27T04:04:22","slug":"lab-week-6-more-arrays","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/infs1609\/blog\/2012\/08\/lab-week-6-more-arrays\/","title":{"rendered":"Lab Week 6 &#8211; More Arrays"},"content":{"rendered":"<p>Finish the exercises from last week than attempt the <strong>Using Arrays<\/strong> exercises in the example problems below.<\/p>\n<p>Here are some hints about how to do exercise 2 from last week. Suppose we have an array of some fixed length, say 10. Java initialises all the elements to zero. Now let&#8217;s assume that we only want to store positive numbers (i.e. greater than 0) in the array. In that case, it&#8217;s convenient to treat zero as meaning an array cell is <em>empty<\/em>. Initially, the array will look like this:<\/p>\n<blockquote><p><code>0 0 0 0 0 0 0 0 0 0<\/code><\/p><\/blockquote>\n<p>Now let&#8217;s insert the number 5. All we have to do is look for the first empty position (i.e. contains 0) and replace it with 5:ow let&#8217;s insert the number 5. All we have to do is look for the first empty position (i.e. contains 0) and replace it with 5:<\/p>\n<blockquote><p><code>5 0 0 0 0 0 0 0 0 0<\/code><\/p><\/blockquote>\n<p>Now let&#8217;s insert 4. It goes before 5, so we have to shift 5 down one place and insert 4 where 5 was:<\/p>\n<blockquote><p><code>4 5 0 0 0 0 0 0 0 0<\/code><\/p><\/blockquote>\n<p>Now let&#8217;s insert 3. It goes before 4, so we have to shift 4 and 5 down one place and insert 3 where 5 was:<\/p>\n<blockquote><p><code>3 4 5 0 0 0 0 0 0 0<\/code><\/p><\/blockquote>\n<p>Inserting 6 is easier because it is larger than any of the existing entries, so it will go into the next empty spot:<\/p>\n<blockquote><p><code>3 4 5 6 0 0 0 0 0 0<\/code><\/p><\/blockquote>\n<p>What happens when the array fills up? What should you do?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Finish the exercises from last week than attempt the Using Arrays exercises in the example problems below. Here are some hints about how to do exercise 2 from last week. Suppose we have an array of some fixed length, say 10. Java initialises all the elements to zero. Now let&#8217;s assume that we only want [&hellip;]<\/p>\n","protected":false},"author":328,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[236],"tags":[],"class_list":["post-375","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/users\/328"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":6,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":380,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/375\/revisions\/380"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}