Output in alphabetical order

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 15
Reputation: wnrqkflwnrqkfl is an unknown quantity at this point 
Solved Threads: 0
wnrqkflwnrqkfl wnrqkflwnrqkfl is offline Offline
Newbie Poster

Output in alphabetical order

 
0
  #1
May 27th, 2009
Hello all, I was building a program which needs to output in alphabetical order and i got stuck.
(Program reads in text file and then do dijkstra's shortest path)

My output is fine except that it is not in alphabetical order....
can anyone help me with this???

here is my code:
  1. void dijkstra(string s, NodeMap &nodes)
  2. {
  3. // check and report or abort
  4. Node* source = nodes.nodemap[s];
  5. if(source==0)
  6. {
  7. cout << "Sorry we don't fly from "<< s << endl; return;
  8. }
  9. reset_nodes(nodes);
  10.  
  11. // put the source into pq and loop until empty
  12. priority_queue<Node *, deque<Node*>, compare>pq;
  13. pq.push(source);
  14. while(!pq.empty())
  15. {
  16. // process least cost node.
  17. Node* curr = pq.top();
  18. pq.pop();
  19. curr->visited = true;
  20. // process neighbors
  21. list<Edge*>::iterator edge;
  22. for(edge = curr->neighbors.begin(); edge != curr->neighbors.end(); edge++)
  23. {
  24. Node *ne = (*edge)->dest;
  25. if(!ne->visited)
  26. {
  27. ne->cost += (*edge)->weight + curr->cost;
  28. ne->visited = true;
  29. ne->back_pointer = curr;
  30. cout << "Cheapest price to "<< ne->name << " = " << ne->cost << endl;;
  31. pq.push(ne);
  32. }
  33. }
  34. }
  35. }
Last edited by Ancient Dragon; May 27th, 2009 at 7:19 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Output in alphabetical order

 
0
  #2
May 27th, 2009
Start with these:Then you should explain what you mean with: ...output should be in alphabetical order... (give an example)
Do you mean the following?
File looks like:
lalal nn
Output should be:
aalllnn
Last edited by tux4life; May 27th, 2009 at 2:24 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 15
Reputation: wnrqkflwnrqkfl is an unknown quantity at this point 
Solved Threads: 0
wnrqkflwnrqkfl wnrqkflwnrqkfl is offline Offline
Newbie Poster

Re: Output in alphabetical order

 
0
  #3
May 27th, 2009
My output should looks like

Enter filename : qantum.txt
Enter start city : Tokyo
Cheapest price to Brussels = 700
Tokyo Paris Brussels
Cheapest price to London = 900
Tokyo Paris London
Cheapest price to Melbourne = 2200
Tokyo Paris London Sydney Melbourne
Cheapest price to New York = 500
Tokyo New York
Cheapest price to Paris = 600
Tokyo Paris
Cheapest price to Sydney = 2000
Tokyo Paris London Sydney

where the city name next to weight is should be in alphabetical order.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 155
Reputation: amrith92 is on a distinguished road 
Solved Threads: 18
amrith92's Avatar
amrith92 amrith92 is offline Offline
Junior Poster

Re: Output in alphabetical order

 
0
  #4
May 27th, 2009
> where the city name next to weight is should be in alphabetical order.

What exactly do you mean by this statement? What "weight" are you referring to? And by "city name should be in alphabetical order", did you mean that the last line(for example) in your Output should look like this - "London Paris Sydney Tokyo"? If not, then try and explain your problem more clearly...
"C++ : Where friends have access to your private members."
C++: You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 15
Reputation: wnrqkflwnrqkfl is an unknown quantity at this point 
Solved Threads: 0
wnrqkflwnrqkfl wnrqkflwnrqkfl is offline Offline
Newbie Poster

Re: Output in alphabetical order

 
0
  #5
May 27th, 2009
Enter filename : qantum.txt
Enter start city : Tokyo
Cheapest price to Brussels = 700
Tokyo Paris Brussels
Cheapest price to London = 900
Tokyo Paris London
Cheapest price to Melbourne = 2200
Tokyo Paris London Sydney Melbourne
Cheapest price to New York = 500
Tokyo New York
Cheapest price to Paris = 600
Tokyo Paris
Cheapest price to Sydney = 2000
Tokyo Paris London Sydney

hmm sry my english isnt perfect....

wat i mean is

those city names comes after Cheapest price to .....

it should be in alphabetical order

where mine is start with

Cheapest price to New York = 500
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Output in alphabetical order

 
0
  #6
May 27th, 2009
What does qantum.txt look like?

Post a sample or attach the file.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 15
Reputation: wnrqkflwnrqkfl is an unknown quantity at this point 
Solved Threads: 0
wnrqkflwnrqkfl wnrqkflwnrqkfl is offline Offline
Newbie Poster

Re: Output in alphabetical order

 
0
  #7
May 27th, 2009
the things in text is...

Sydney New York 1300
New York Paris 1200
London Sydney 1100
Sydney London 1300
Paris New York 900
New York London 700
London Paris 200
Sydney Paris 900
Paris London 300
Brussels Paris 200
London Brussels 300
Sydney Brussels 700
Brussels New York 400
Paris Brussels 100
Tokyo New York 500
Tokyo Paris 600
Sydney Tokyo 300
Sydney Melbourne 200
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Output in alphabetical order

 
0
  #8
May 27th, 2009
Please post an example of your full code to test.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 15
Reputation: wnrqkflwnrqkfl is an unknown quantity at this point 
Solved Threads: 0
wnrqkflwnrqkfl wnrqkflwnrqkfl is offline Offline
Newbie Poster

Re: Output in alphabetical order

 
0
  #9
May 27th, 2009
Here is my full code
Attached Files
File Type: cpp fly.cpp (3.2 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Output in alphabetical order

 
0
  #10
May 27th, 2009
Your code doesn't do anything.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC