struct looks like this:

``````struct ListNode;
typedef ListNode* ListType;
struct details
{
char first_name[20];
char last_name[20];
int  start_number;
int  end_number;
};

struct ListNode
{
details data;
ListType next;
};
ListType list = NULL;

I have a circular linked list that i bubblesort, and the swap function for it now looks like this:

``````void Swap(ListType& a, ListType& b)//when called b is always a->next
{
ListType prevNodeA;
ListType tempPtr = a;
ListType AfterNodeB = b->next;

while(tempPtr->next!=a)//find the node before a
{
tempPtr = tempPtr->next;
}
if(tempPtr->next==a)
{
prevNodeA = tempPtr;
}
{
b->next = prevNodeA->next;
prevNodeA->next = a->next;
a->next = AfterNodeB;
}
else
{
b->next = prevNodeA->next;
prevNodeA->next = a->next;
a->next = AfterNodeB;
}
};``````

I am fairly certain that im swapping the pointers right, the problem lies in assigning the head, because it never reads the else part. The first time im calling the fuction, a is the head of the list and it is stuck in that loop.
Sort function:

``````void Sort(ListType* PointerToHead)
{
ListNode *temp1;
ListNode *temp2;

{
for(temp2 = temp1->next ; temp2->next!=head; temp2 = temp2->next)
{
if (Smallest(temp2->data, temp1->data))
{
Swap(temp1, temp2);
}
}
}
};``````

so my question is, how do i reassign the head while in a circular linked list?
(i only have a head node in the linked list, no tail). the pointer of the last node points to the head.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.