Adobe Interview Question
Software Engineer / Developersmaintaining a generic linked list and then sorting the list accordingly while manipulating pointers seems to be the most memory efficient solution. What say?
i am not sure what interviewer want..
he said that, sorting function can sort anything ..
i replied that if comparision is not define how fuction can sort element ... i gave example like comparision of complex number is not defined.. but user can define by comparing real part or complex part or both ... i questioned that how generic function find out this !!!
i am not sure what interviewer want..
he said that, sorting function can sort anything ..
i replied that if comparision is not define how fuction can sort element ... i gave example like comparision of complex number is not defined.. but user can define by comparing real part or complex part or both ... i questioned that how generic function find out this !!!
i am not sure what interviewer want..
he said that, sorting function can sort anything ..
i replied that if comparision is not define how fuction can sort element ... i gave example like comparision of complex number is not defined.. but user can define by comparing real part or complex part or both ... i questioned that how generic function find out this !!!
Hi.
Any sorting algo has 2 basic operations: comparision & swapping.
Hence if we have 2 generic API's for them it would be enough.
typedef void (*Swapfunc)(void *element_1, void *element_2);
typedef int (*Cmpfunc)(void *element_1, void *element_2);
void GenericSort(void *array, uint32_t nbElems, Swapfunc swapFunc, Cmpfunc cmpFunc);
generic Qsort in C. May be STL is also providing same kind of thing.
- Tulley February 14, 2011void qsort(void *base, size_t nmemb, size_t size, int (*compare)(const void *, const void *));