Re: Elementary but surprisingly difficult.



Albert van der Horst wrote:
The main problem is that the content cannot be placed
on the stack they cannot be compared with <> etc.

I don't see the big problem. If you can't place the content on the stack,
place a pointer. And compare with whatever compare function you need. If
you want this a library function like qsort, define that your array is an
array of pointers to the actual structures, and that you have a deferred
word for the actual comparison. This will compare for <= (whatever that is
for your objects), and is used for both the qsort and the duplicate
removal. You just have to make sure that the comparison order is the right
one, i.e. if you expect a to be <= b, compare b <= a for duplicate removal
(will only be true if b=a).

--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://www.jwdt.com/~paysan/
.



Relevant Pages

  • Re: Test if pointer points to allocated memory
    ... >> or one past the same object or array. ... When two pointers are compared, the result depends on the relative ... pointers to structure members declared later compare ... > The typical implementation of automatic storage is on the program stack. ...
    (comp.lang.c)
  • Re: sorting 2d arrays using qsort
    ... > That's a dangerous way to compare two signed integers. ... > You can't do it with qsort because qsort tries to directly exchange two ... C doesn't directly supply an exchange operation for any type, ... qsortdoesn't know or care about the type of the elements of the array ...
    (comp.lang.c)
  • Re: Memory Allocation: new int[s] vs. vector<int>p; p(s)
    ... >> If you want to nitpick, the terms heap and stack do not appear in the ... > path from a try block to a throw-expression is called stack unwinding. ... > push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare ...
    (comp.lang.cpp)
  • Re: qsort that also keeps track of the order without using struct
    ... different array of equal length. ... At no time does qsort inform you of the swap order. ... function that you provide to qsort should not compare the elements at ...
    (comp.lang.c.moderated)
  • Re: qsort
    ... > The compare function is incorrect. ... the two pointers point to or just after the same array. ... qsort() guarantees this obviously ...
    (comp.lang.c)