| | |
Output in alphabetical order
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2009
Posts: 15
Reputation:
Solved Threads: 0
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:
(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:
c Syntax (Toggle Plain Text)
void dijkstra(string s, NodeMap &nodes) { // check and report or abort Node* source = nodes.nodemap[s]; if(source==0) { cout << "Sorry we don't fly from "<< s << endl; return; } reset_nodes(nodes); // put the source into pq and loop until empty priority_queue<Node *, deque<Node*>, compare>pq; pq.push(source); while(!pq.empty()) { // process least cost node. Node* curr = pq.top(); pq.pop(); curr->visited = true; // process neighbors list<Edge*>::iterator edge; for(edge = curr->neighbors.begin(); edge != curr->neighbors.end(); edge++) { Node *ne = (*edge)->dest; if(!ne->visited) { ne->cost += (*edge)->weight + curr->cost; ne->visited = true; ne->back_pointer = curr; cout << "Cheapest price to "<< ne->name << " = " << ne->cost << endl;; pq.push(ne); } } } }
Last edited by Ancient Dragon; May 27th, 2009 at 7:19 am. Reason: add code tags
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?
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."
•
•
Join Date: May 2009
Posts: 15
Reputation:
Solved Threads: 0
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.
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.
> 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...
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."
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."
•
•
Join Date: May 2009
Posts: 15
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: May 2009
Posts: 15
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- HOw to sort the array of strings in c in alphabetical order of words.. (C)
- display in alphabetical order using singly linked list? (C)
- search form with alphabetical order (PHP)
- sorting strings into alphabetical order (Java)
- search in alphabetical order (VB.NET)
- put a sentence in alphabetical order.... (Java)
- Alphabetical Order (Python)
Other Threads in the C++ Forum
- Previous Thread: Sorry but im new at this but i have some questions
- Next Thread: how to ignore the ENTER key
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






