Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

I have two queues Q1 , Q2 and I want to execute the contents into queue Q3. The queue are shown front ( left ) to rear ( right ).

Contents of Q1 and Q2

Q1: 42 30 41 31 19 20 25 14 10 11 12 15

Q2: 1 4 5 4 10 13

My algorithm I came up with is shown below ;

1 Q3 = createQueue

2 count = 0

3 loop ( not empty Q1 and not empty Q2)

1 count = count + 1

2 dequeue (Q1 , x )

3 dequeue (Q2 , y )

4 if ( y equal count )

1 enqueue (Q3 , x )

now I have tried several times with different solutions. I think the Not is confusing me. If you can help please show me how to work the problem to get the correct ans. of what the contents would be in Q3. I get the first number as 4 that stays ok but the rest never stay in the same position . also please explain the Not. It is a logical Not is it so. where, when if it becomes true it turns false? At least thats the way I read it in my C book.

Contents of Q1 and Q2

Q1: 42 30 41 31 19 20 25 14 10 11 12 15

Q2: 1 4 5 4 10 13

My algorithm I came up with is shown below ;

1 Q3 = createQueue

2 count = 0

3 loop ( not empty Q1 and not empty Q2)

1 count = count + 1

2 dequeue (Q1 , x )

3 dequeue (Q2 , y )

4 if ( y equal count )

1 enqueue (Q3 , x )

now I have tried several times with different solutions. I think the Not is confusing me. If you can help please show me how to work the problem to get the correct ans. of what the contents would be in Q3. I get the first number as 4 that stays ok but the rest never stay in the same position . also please explain the Not. It is a logical Not is it so. where, when if it becomes true it turns false? At least thats the way I read it in my C book.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think you do, because as you say, 4 comes as first number, and that's what should be happening:

I will try to re-write your loop, maybe will be clearer

while(Q1 and Q2 have some numbers in them){

count=count +1;

take one element(from left I assume)form Q1 and put in x

take one element from Q2 and put in y

if (y==count)put y into Q3

}

so as you see, when the counter will be equal 4, we will have in y fourth element of Q4, which is 4, so it goes to Q3

at the end of the loop you should be having only 4 in your Q3, because any other elament doesn't happen to be equal count when it is dequeued from Q2

if you are trying to do something else, explain more

Q1: 42 30 41 31 19 20 25 14 10 11 12 15

Q2: 1 4 5 4 10 13

1: count=1, x=42, y=1, y==count-false

2: count=2, x=30, y=4, y==count-false

3: count=3, x=41, y=5, y==count-false

4: count=4, x=31, y=4, y==count-true, put 4 in Q3

5: count=5, x=19, y=10, y==count-false

6: count=6, x=20, y=13, y==count-false

Q2 becomes empty

end

This book uses a Approach to Pseudocode with C.....

What I am tring to determine that imagine I had two Queue's and the data as listed , and the algorithm I am writing ( hope it is right ) what would be the contents of Queue 3 after the execution of the example shown.

The book is unclear as what else to do , the little on ADT isnt enough to help me.

Now since I am new to this Data Structure and have been programming for a number of years( with several languages learned).

I am not sure what one can do with this , CAN I put THIS to C code to test and run it (HOW) or can you only test it by hand?

I tried to contact the company where I purchased the book. Written by "Gilberg and Forouzan was reccommended," but they will not sell the answer book, only to school, if you know what I mean. Sure makes it hard to continue your upgrade .

I am tring to improve my skills in programming.

I came across your site and started to look thru the listing but didnt find what I needed. Is there a way to search for what I need as listed above? For I will be using your site as I use this book.

thank you

1 The solution given by Gula is almost right but 31 goes into Q3 instead of 4.(Note enqueue (Q3 , x ); Is this correct as stated by another person????

2I am not sure what one can do with this , CAN I put THIS to C code to test and run it (HOW) or can you only test it by hand?

Please read the first comment and let me know , I dont have that many points . If you dont know let me know , if there is a way to recover the last points or however the system works let me know.

awaiting your reply , any other help would be great.

to say truth, I didn't clearly understand the last message you posted, so I was hoping someone who did understand would reply..

>>The solution given by Gula is almost right but 31 goes into Q3 instead of 4.(Note enqueue (Q3 , x ); Is this correct as stated by another person????

It's true, I missed that it was x, you see, if you had y there in enqueue (Q3 , x ); I mean, if it was enqueue (Q3 , y ); then the result you were getting would make sence, not that it is x... I don't really understand how you are getting 4 in there

few questions, just to get clearer what you want...

>>CAN I put THIS to C code to test and run it (HOW) or can you only test it by hand?

what do you mean by "THIS"? the peice of algorithm? or something like "this" that you can use in java, that would mean the class you are currently in...?

>>I have two queues Q1 , Q2 and I want to execute the contents into queue Q3.

What do you mean by "execute"? Put all elements Q1 and Q2 have into Q3 or there is some logic that you want to follow to fill it up?

like you gave

Q1: 42 30 41 31 19 20 25 14 10 11 12 15

Q2: 1 4 5 4 10 13

what are you expecting Q3 to have after your algorithm?

I'm afraid to underestimate your knowelege, some people don't like that, ...but it is really hard to answer someone's questions without knowing how much they know. It would really help to know where are you at.

So, please explain if you are comfortable with the concept of queues, using enqueue and dequeue and if there are problems with C syntax..

For that algorithm above, if you have code, please post it, if you don't have it and don't know how to start, just say that...so people know where to start to help from..

thank you

What I am looking for is : What would be the contents of Q3 after the above algorithm code is executed, using the values giving for Q1 and Q2? I am not sure what to expect.

I am tring to take the two queue's (Q1,Q2) and place them into a third queue (Q3).

The queue contents are shown front ( left ) to rear ( right ).

Q1: 42 30 41 31 19 20 25 14 10 11 12 15

Q2: 1 4 5 4 10 13

Second : How to solve it by hand and get a answer ?

YOU SHOWED ONE METHOD IS THAT CORRECT?

Third : How to write the above algorithm in C code?

I hope this is clearer.

Yes ! I have done both C & C++ for a number of years and at work I am tring to pick up Data Structure on my own. This part is new to me, so please excuse the confusion .

----------------

GULA

on your example you show it counts 6 times with just one number going to Q3 , which was 4( thats all ). Now we know it is 31. I am not sure how I kept coming up with 4 but if you came up with 4, some how I must of over looked the x or y.

My recommendation, which I will post in the Cleanup topic area, is to

PAQ, refund points (some interesting progress, but asker is not satisfied).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg

EE Cleanup Volunteer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

I'm not real certain but it looks like you want to take a number out of Q1 according to an index in Q2. If this is the case then i can see a few easier ways to do this. Respond with a better explination and I will try to help you. If I was write in my assumtion then you may consider taking each element out of Q2 and then using that as an index to accsess the corresponding element in Q1 to storein Q3.