Note that there are some explanatory texts on larger screens.

plurals
  1. POadjacency matrix in C++
    text
    copied!<p>I need too create an adjacency matrix in C++ for data read from a file like this</p> <pre><code>ABC CDE 100 ZXY ABC 25 TER ZXY 11 POP ABC 66 ABC CDE POP TER ZXY ABC 100 CDE POP 66 TER 11 ZXY 25 #include &lt;fstream&gt; // for std::ifstream #include &lt;sstream&gt; // for std::istringstream #include &lt;cstring&gt; // for std::string and std::getline #include &lt;iostream&gt; #include &lt;ctype.h&gt; #include &lt;stdio.h&gt; #include&lt;algorithm&gt; #include &lt;string.h&gt; using namespace std; #define MAX 30 #define WORD 3 string* currentArray; typedef struct node{ int nodeId; string destCity[MAX]; string arrCity[MAX]; int time; }NODE; typedef struct edge{ int adjoin; int distance; }EDGE; typedef struct graph{ NODE cityNode[MAX]; EDGE e[MAX][MAX]; }GRAPH; GRAPH graf; bool removeDuplicates(int count,string* tempArray){ for (int i = 0; i &lt;= count; i++) { int n=0; bool matching = false; for (int j = 0; (j &lt; i) &amp;&amp; (matching == false); j++){ if (currentArray[i] == currentArray[j]) matching = true; } //if (!matching) tempArray[n] = currentArray[i]; } return false; } void MergeA(int low ,int mid , int high) { int i = low, j = mid+1 , k = low; string Temp[MAX]; while(i &lt;= mid &amp;&amp; j &lt;= high) { if( currentArray[i] &lt;= currentArray[j] ) { Temp[k].assign(currentArray[i]); i++; } else { Temp[k].assign(currentArray[j]); j++; } k++; } if(i &gt; mid ) { for(int h = j ;h &lt;= high ; h++ ) { Temp[k].assign(currentArray[h]); k++; } } else for(int h = i; h&lt;= mid ; h++ ) { Temp[k].assign(currentArray[h]); k++; } for(int i = low; i &lt;= high ; i++) { currentArray[i].assign(Temp[i]); } } void MergeSortA(int low , int high) { int mid = 0; if(low &lt; high) { mid = low + (high-low)/2; MergeSortA(low , mid); MergeSortA(mid+1,high); MergeA(low,mid,high); } } int main() { std::ifstream infile("theWords.txt"); std::string line; string departureCity[MAX],arrivalCity[MAX]; int time[MAX]; int count = 0; while (std::getline(infile,(line)) &amp;&amp; count&lt;30){ std::istringstream iss(line); if ((iss) &gt;&gt; departureCity[count] &gt;&gt; arrivalCity[count] &gt;&gt; time[count]){ //departureCityCopy[i] std::cout &lt;&lt; "From : " &lt;&lt; departureCity[count] &lt;&lt; " To : " &lt;&lt; arrivalCity[count] &lt;&lt; " Duration " &lt;&lt; time[count] &lt;&lt; "\n"; graf.cityNode[count].destCity = departureCity[count]; count++; }else{ // error processing that line } } std::string cpyDepartureCity[MAX],cpyArrivalCity[MAX]; int cpyTime[MAX]; std::copy(departureCity,departureCity+count,cpyDepartureCity); std::copy(arrivalCity,arrivalCity+count,cpyArrivalCity); std::copy(time,time+count,cpyTime); currentArray= cpyDepartureCity; MergeSortA(0,count); cout&lt;&lt;"before dup"&lt;&lt;endl; //removeDuplicates(count,&amp;currentArray[1]); for(int i = 0; i &lt;= count ; i++){ cout &lt;&lt; cpyDepartureCity[i] &lt;&lt;endl; } currentArray= cpyArrivalCity; MergeSortA(0,count); /*for(int i = 0; i &lt;= count ; i++){ cout &lt;&lt; cpyArrivalCity[i] &lt;&lt;endl; }*/ } </code></pre> <p>I am reading into an array ,and then using merge sort to sort them alphabetically I have created a node but I am not sure how to go about from here I have been at it for hours with no success Please help </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload