Hi. I am currently working on a doubly-linked and circular list (is that term correct? , I am working all of this in french

). I am done on every part (inserting, removing) and now I'm trying to add a sorting method to my class. For now, I'm trying a simple bubble sort algorithm to at least have something working.
I though of some easy ways of getting it done, but since I am a very stubbord person (sometimes), I'd like to do it a certain way. I am trying to sort directly into my list, permuting element as the sorting goes. I am aware my code is probably something worth laughing at, but Hey!, I'm starting and trying to learn.
Here is my code so far :
CODE
node * temp = head;
for (int cpt = 1;cpt <= nbrElements * ((nbrElements - 1) / 2);cpt++)
{
if (temp->data > temp->next->data)
permute(temp,temp->data);
temp = temp->next;
}
if ((cpt + 1) % nbrElements == 0)
temp = head;
My for condition is something I found about bubble sorting, which represent the maximum number of comparaisons the algorithm has to do. This code succeeded in sorting a 3 element list. However, it gives some weird stuff when I throw something bigger. Since my list is circular, I thought I could do it this way by somehow I was not able to achieve it yet.
So I'm here begging for mighty help! Thanks a lot