Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

AppylPye

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?

  • 9 months ago
  • 9 months ago

  • This Question is Closed
  1. AlbionsRefuge
    Best Response
    You've already chosen the best response.
    Medals 1

    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

    • 8 months ago
  2. AppylPye
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 8 months ago
  3. AlbionsRefuge
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • 8 months ago
  4. AppylPye
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 8 months ago
  5. AlbionsRefuge
    Best Response
    You've already chosen the best response.
    Medals 1

    That's it - yes that was what I read. Thanks!

    • 8 months ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.