Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Iterators and Linked Lists
    primarykey
    data
    text
    <p>So I'm trying to assign the values of one linked list to another, exterior linked list (not in the current method) using iterators.</p> <pre><code>LIST_ITER i = temp.begin(); while(bLeft != end) { *bLeft = *i; ++i; ++bLeft; } </code></pre> <p>This is only a portion of the code, the iterator i is for the temp list, whereas bLeft and end are the beginning and end (respectively) of the exterior list.</p> <p>This above code, however, is producing a strange error where I get a bunch of strange text (some of it actually says something about Microsoft Windows Compatible etc. etc.) that when run on a Unix machine just gives a Segmentation Fault.</p> <p>EDIT: Here is the code in its entirety:</p> <pre><code>#include &lt;iostream&gt; #include &lt;list&gt; #include &lt;string&gt; #include &lt;iterator&gt; using namespace std; typedef list&lt;string&gt; LIST; // linked list type typedef LIST::size_type LIST_SIZE; // size type for list, e.g., unsigned typedef LIST::iterator LIST_ITER; // iterator type typedef LIST::value_type LIST_CONTAINS; // type in the list, i.e., a string void merge_sort(LIST_ITER beg, LIST_ITER end, LIST_SIZE sz); void merge(LIST_ITER bLeft, LIST_ITER bRight, LIST_ITER end); int main() { LIST l; LIST_CONTAINS v; // Read in the data... while (cin &gt;&gt; v) l.push_back(v); // Merge the data... LIST_ITER i = l.begin(); LIST_ITER iEnd = l.end(); merge_sort(i, iEnd, v.size()); // Output everything... for (; i != iEnd; ++i) { cout &lt;&lt; *i &lt;&lt; '\n'; } system("pause"); } void merge_sort(LIST_ITER beg, LIST_ITER end, LIST_SIZE sz) { if(sz &lt; 2) { return; } else { LIST_SIZE halfsz = (distance(beg, end)/2); //half of list size LIST_ITER i1End = beg; //iterator for the end of the first list advance(i1End, halfsz); //advance to the midpoint i2 = i1End++; //iterator for the beginning of the second list --end;//iterator for the end of the second list merge_sort(beg, i1End, halfsz); //recursively pass first list merge_sort(i2, end, halfsz); //recursively pass second list } merge(beg, i2, end); } void merge(LIST_ITER bLeft, LIST_ITER bRight, LIST_ITER end) { LIST temp; LIST_ITER beg = bLeft; LIST_ITER halfw = bRight; LIST_ITER i = temp.begin(); while(beg != bRight &amp;&amp; halfw != end) { if(*beg &lt; *halfw) { temp.push_back(*halfw); halfw++; } else { temp.push_back(*beg); beg++; } } while(beg != bRight) { temp.push_back(*beg); beg++; } while(halfw != end) { temp.push_back(*halfw); halfw++; } while(bLeft != end) ///HERE IS THE PREVIOUSLY POSTED CODE { *bLeft = *i; ++i; ++bLeft; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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