We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Graphics and Linked List Under C++

seyedsaatchi asked
Medium Priority
Last Modified: 2013-12-14
1 - I Have Borland C++ Compiler (DOS) 3.0 , My Problem .. When i tried to load my graphic program, i've got error message in this compiler. althought i loaded this program under different system it works .. but under my compiler doesn't.

2 - I tried to do my Linked list and i done it .. my problem  how can i do my SORTING PROGRAM under Linked List ...

Watch Question

1 : ???

Each graphics subsystem is usually compiler & system dependent. Can you give some more
infos( e.g. on which 'different' system did it work)?


I remember there are various methods to sort linked lists. I know a quite simple method, it isn't
the fastest i think ...

a) Assign all your linked list items some sort of hash value which is sort order dependent,
perhaps like this:

unsigned long buildHash(char *text)
unsigned long ulValue=0;
int nPos;
for(nPos=0;nPos<4;nPos++) {
if(text[nPos]==0) break;
ulValue |= ((unsigned char)text[nPos])<<((3-nPos)*8);
return ulValue;
// example: HELLO -> 0x48454c4c

Then define a struct which takes the linked list item and its hash value:

struct _helper {
linkedlistitem *item;
unsigned long hash;

Build an array so that each linked-list item is contained, and then you can use the qsort()
function of C( or the STL implementation).
Then you can either use a bubble sort on the linked-list items which have the same hash
value - or you can proceed like above, assign those items with the same hash value a new
array, where the hash value starts with the 4th character.
In the worst case (all items are identical), you'll get O(N*N), in the best case, where all
(first) hash values are different, you'll get O(N).
Unlock this solution and get a sample of our free trial.
(No credit card required)

Bubble sort is the slowest algorithm possible. Don't use it  ...
If you sort more than 1000 elements, even a Pentium II 400 goes down :)

Don't get me wrong - i don't want to insult you in any way.
But bubble sort is *really* slow. If we're talking of only 200 elements, it's okay :)

Snolger !
Thank you for your comment. It is good to share the knowledge.


sganta, please don't get me wrong - i just *hate* the bubblesort algorithm.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.