Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting a vector of structs having pointer
    primarykey
    data
    text
    <p>Below is my code:</p> <pre><code>typedef struct { unsigned page; unsigned slot; } RID; //Below struct has the Key on which I want to apply the sorting struct LeafDataEntry { void *key; RID rid; }; //This is the sorting function I am using bool leadNode_Key_asc( const LeafDataEntry &amp;a, const LeafDataEntry &amp;b){ return strcoll((char *)a.key, (char *)b.key) &gt; 0; //(strcmp((char *)a.key, (char *)b.key) &gt; 0); } int main(){ vector&lt;LeafDataEntry&gt; lde; char a[4] = {'D', 'B', 'C', 'D'}; RID aRID = {0,0}; char b[4] = {'A', 'C', 'B', 'A'}; RID bRID = {0,1}; unsigned size = sizeof(unsigned); lde.resize(2); char *tempPtr = (char *)malloc(8 + sizeof(RID)); memcpy(tempPtr, &amp;size, 4); tempPtr += 4; memcpy(tempPtr, a, 4); tempPtr -= 4; lde[0].key = malloc(8); memcpy(lde[0].key, tempPtr, 8); memcpy(&amp;lde[0].rid, &amp;aRID, sizeof(RID)); memcpy(tempPtr, &amp;size, 4); tempPtr += 4; memcpy(tempPtr, b, 4); tempPtr -= 4; lde[1].key = malloc(8); memcpy(lde[1].key, tempPtr, 8); memcpy(&amp;lde[1].rid, &amp;bRID, sizeof(RID)); std::sort(lde.begin(), lde.end(), leadNode_Key_asc); cout &lt;&lt; "Sorted Data :: " &lt;&lt; endl; for(int j=0; j&lt;2; j++){ cout &lt;&lt; "KEY :: " &lt;&lt; (char *)(lde[j].key); cout &lt;&lt; ", RID ::" &lt;&lt; "{" &lt;&lt; lde[j].rid.pageNum &lt;&lt; ", " &lt;&lt; lde[j].rid.slotNum &lt;&lt; "}"; } return 0; } </code></pre> <p>I want to sort the above lde vector based on the *key value. It's not working with the way given above.</p> <p>NOTE: I cannot change the data types of any of the structs listed above.</p>
    singulars
    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.
    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