Jump to content

Quack assignment from Data Structures class

On another note capacity = 4, nItems = 2 in your example.

Ok, I'm getting closer :lol:

I think I've misunderstood what nItems is, I've been assuming it's the number of

elements currently stored in the array, so for

Array Index: [0 1 2 3]Elements:    [a b c d]Front/Back:  [F B    ]
I would have four elements ('a','b','c','d') stored in the array, with 'a' being the current Front

('F') and 'b' being the current back ('B').

If nItems=2 then, why is that exactly?

P1X3 you don't need the if statement....just go r = r%nItems, no matter what r is.

True, r%nItems will always give you the desired result, even if r<=nItems.

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to post
Share on other sites

Ok, I'm getting closer :lol:

I think I've misunderstood what nItems is, I've been assuming it's the number of

elements currently stored in the array, so for

Array Index: [0 1 2 3]Elements:    [a b c d]Front/Back:  [F B    ]
I would have four elements ('a','b','c','d') stored in the array, with 'a' being the current Front

('F') and 'b' being the current back ('B').

If nItems=2 then, why is that exactly?

nItems starts out at 0, and whenever a push is made, nItems gets incremented.  nItems is essentially there as an easy way to get how many items there are from the start of the queue to the end.  Although you have 4 items stored in the array if you went like this, push a, push b, push c, push d, pop, pop.  You would end up like your example, but since c and d are garbage they don't get counted in the number of items there are.

0b10111010 10101101 11110000 00001101

Link to post
Share on other sites

nItems starts out at 0, and whenever a push is made, nItems gets incremented.  nItems is essentially there as an easy way to get how many items there are from the start of the queue to the end.  Although you have 4 items stored in the array if you went like this, push a, push b, push c, push d, pop, pop.  You would end up like your example, but since c and d are garbage they don't get counted in the number of items there are.

Ah, ok, I think we were just not talking about the same example, I was always talking

about the last two not being garbage. Ah, the hilarity of misunderstandings. :lol:

But yes, 4xpush+2xpop would give me the same result as yours, completely agree on that.

I've tried to actually create an array with b,c not garbage and a=Front and b=Back going

by the actual code, but so far I haven't actually found a way yet. So from what I can tell

it works indeed. I was just going off an artificial example that can't actually be achieved

(at least as far as I can tell so far). Of course the code would fail for that, silly me :lol:

EDIT:

 

Is this true? The "Quack" part.

Just so you don't think I've overlooked that part, but I haven't been able to find any

information on this. If you really wanted to know you could always look at the source code,

although I doubt that would be readable for non-experts. From what I've heard the C++ standard

library is mostly heavily optimized (as I would hope it to be), but that makes it a bit tricky

to decipher. I haven't personally looked at it though ;)

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to post
Share on other sites

Congratulations, by chance did you make any modifications to your priorly uploaded code?

 

Haven't looked too far into this but here is an extra challenge for any go getters who want to try this:

As noted in your instructor's example when you reverse an array, the array has nItems/2 items swapped.  While this is a common way to reverse an array, in this assignment there should be a reverse function that takes constant time.  By forcing reverse to be constant time, your rotate, print, pops and pushes will be effected.  The affects on the function will be minor (at least in my solution, which I will post later), and shouldn't add any or much computational time to any function.

 

So in effect my challenge is make it so the least amount of swaps has to be done, without sacrificing the current speed of your program.

0b10111010 10101101 11110000 00001101

Link to post
Share on other sites

Okay I am sorry for bumping and offtopic, but this just made my day.

Awesome, congratulations! And I wouldn't say it's off-topic, in fact I'm glad to know

our support actually paid off (or at least that's what I like to tell myself :lol: ).

Haven't had time to look further into this yet, but as a long term project I think

I should find the time to do some data structures at some point. Either this or

something similar. After all, there are many data structures waiting to be re-implemented

by amateurs like myself. Although I'll probably have to do something similar in college

anyway, so I might as well get a bit of a head start. ;)

Either way, this was a very nice exercise to dust off my C++ again after letting it

lay dormant for more than two years. I definitely feel a bit of a rustiness, but more

when it comes to designing algorithms than actual language syntax. I'm certainly looking

forward to taking apart WanderingFool's implementation. :)

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to post
Share on other sites

Don't really have any ideas at the moment, sorry P1X3.

 

Anyways the two solutions the standard way I would do the assignment and then the reversal using only 4 lines of code.

 

mySol.zip

mySol.zip

mySol.zip

0b10111010 10101101 11110000 00001101

Link to post
Share on other sites

Only thing that comes to mind is artificial examples, nothing practical at the moment.

@WF

<offtopic>

The one thing that looks like something to me is the first one, but maybe I'm just

not l33t enough :lol:

ba ad f0 0d    (hex)º­ð             (text)uq3wDQ==       (base64)186 173 240 13 (ASCII DEC/CHAR)
</offtopic>

Anyway, I'll take a look at your solution, I'm certainly intrigued. :)

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×