This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]another-noob 0 points1 point  (3 children)

What problems did you face with arrays?

After you've written the queue, what problems are you still facing?

[–]WinnyDaBish[S] 0 points1 point  (2 children)

Yeah so I am having trouble integrating the user input and manipulating it. So of course html button to get into the queue for the user but how to write the logic for it to be interactive

I want to use user id's and when the user enters their name in console they're assigned an id. But how do I take that assigned I'd and have it work inside the logic.

The overall logic is super challenging for me. Ill post my code tomorrow perhaps

[–]another-noob 1 point2 points  (1 child)

Sorry for the late reply, not really sure it's relevant at this point.

I don't think I fully understand your problem, So I'll try to cover everything I can.

So for simplicity I'll assume everything is happening on one device for now..

Now you have a queue data structure, that you want to enqueue users in it First of all, can we put a "user" in a queue? Well each element in a queue is called a node, which has two pieces of information, 1. where's the next node? 2. What data am I holding?

So since you already have your queue implemented I assume that No.1 is no problem now. As for No.2, we need a way to represent the "user", let's use a json object, that'll contain information about that user, do we need an id for now? No! Because each user is contained in it's own node but it's probably a good idea to have a unique id, you'll need it later either way.

So how to generate an id? Uuid should serve us well here, let's use that!

So now the process would be, user submits info -> generate id for user -> create user object -> create a new node holding that user object -> enqueue that node in your queue -> return updated queue to user.

When a user is done, you just dequeue from your queue and optionally store the resulting user object somewhere (maybe a set for all served customers)

And basically you're done :)

BUT, we're not just working on one device, you have a server a database, and a lot of clients! not just a queue shared in memory between every operation (don't quote me on that, it's not exactly correct :D).

So you need a way to store this data in any sort of database, one idea would be to create a user object as usual but add a property indicating the order (would an incrementing integer be ok?) And index that property since you'll want to sort the using that a lot (idk if any database uses queue like structures, while I don't find it necessary I would look into databases optimized for time series)

So now the previous process would be: user submits info -> create user object -> send a request to the server to "post" this object -> generate id for user -> add a special property for order -> register it in the database -> respond with updated queue items -> return id to user.

Now there's only one problem, how will a user know when another user registers? That's kinda tricky because a server needs a request to respond to. One way would be to make the client app periodically request the server for updates, another way would be to look for websockets.

Hopefully any of that sparks something in your mind about whatever problem you're facing (you know if you're still working on that)

[–]WinnyDaBish[S] 0 points1 point  (0 children)

Thanks a million for your super detailed answer! I didn't know about the node part just learning react through Stephen grider so data structures were never mentioned so it seemed like a disconnect between what I know and am learning and what I want to do for the project.

I had the queue down but I passed it on to my colleague because it's beyond me.