anonymous
  • anonymous
Following is a solution for Mechanical MOOC MIT OCW 6.189 Homework 3, Exercise 3.6 - Your First Class, in which we need to create a Queue. http://ideone.com/WCxNBy The program inserts and removes "random" integers to test the Queue. The code was written for Python 3. Another strategy for creating the Queue class could be to store the values in a list instead of in a private __Node class. Does anyone else have a solution for this exercise?
Classes
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Ha, I tried to make the queue a list at first but then I couldn't decide how to control the FIFO bit so I made it a string instead. This will need revisited for sure! http://ideone.com/58GkH1
anonymous
  • anonymous
Yeah, I had thought of using a list, which would have been simpler, but chose instead to create Nodes and maintain pointers to the front and back of the Queue. With a list implementation, append(item) could be used to add the item to back of the Queue. To remove an item from the front of the Queue, item = theList.pop([0]) would remove the item at the 0th position in the list, and return it, assigning it to item. Another means of doing this could be item = theList[0], and then theList = theList[1:]. We should consider the (non)efficiency of these operations, though.
anonymous
  • anonymous
Arg, well I did start with the pop() and append() and the slice but then I started thinking about something that was mentioned somewhere? (ha!) about the order of the items might not be as expected. I've gone and done some reading and I think I've straighten my brain out on that, but I can't remember yet what exactly was being talked about that got me on the wrong track.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
With a list, the order of the items would be reliable. But you may have read that in a dictionary, there is not an inherent ordering to the items. In other words, if you assign the following to a dictionary ... d = {1: "one", 2: "two", 3: "three", 4: "four"} ... and then ... print d ... the items will not necessarily print in the same order in which they were assigned or added to the dictionary, nor can they be relied upon to print according to any ordering that is implied by the keys.
anonymous
  • anonymous
That's it - yes that was what I read. Thanks!

Looking for something else?

Not the answer you are looking for? Search for more explanations.