hi,

so i have a question relating to sending data in a sequence. i have a class evenvent that reads the data from a txt file. that class has to send data to 2 comunication line async and sync. data sent to async is for ex: 'new' . data that is sent to sync is 'query' and it gets a result back

the data in txt file is in sequence 1,2,3,.... when i sent it to the 2 coommunication line i break the data and put it into 2 queues. one queue is for asyn and the oother is for sync. theses 2 class has to sent to another class A,

my question is how do i process the data in sequence again.

appreciate a way to do it

thanks

so i have 2 queues with data. data has a unique identification. i queue starts with 1,2,3,4, and then the next queues may have the 5 6 7data and so on. So when it comes to class B, it has to be in sequence so that class B can process it in order.

hope i made it clear

it is in acending order for ex: queue A has 1,2,3,4, 7,8 queue B has 5,6,9,10

it is like above

Hi,
It sounds so obvious that I probably miss the question :
Create another stack C.
Dequeue the first element from A (=>1) and B(=>5)
Compare these elements and enqueue the smaller into C (=>1)
Dequeue a new element from A (=>2) (because you have used the previous element from A)
And so on, when A and B are empty, you have a sorted stack C.

Hi,
It sounds so obvious that I probably miss the question :
Create another stack C.
Dequeue the first element from A (=>1) and B(=>5)
Compare these elements and enqueue the smaller into C (=>1)
Dequeue a new element from A (=>2) (because you have used the previous element from A)
And so on, when A and B are empty, you have a sorted stack C.
Patrick.

is there any solution for multiple threads?

Patrick, your soultion is for a single thread of control right?

If your stack A and B are located in distinct threads, each of these thread can write in a common C stack. But you must lock the C stack before writing in it. For this, I use Monitor.Enter(Cstack) to lock and Monitor.Exit(Cstack) when done, to free the data. Is this Monitor class clear for you ?

This article has been dead for over six months. Start a new discussion instead.