How to sort alphabetically the link list?

Example:

pHead
B

pSecond
A

pLast
C

Result:

pSecond
A

pHead
B

pLast
C

Just use a normal sort algorithm, there are lots of them and google will show you the c/c++ source code for most of them. When its time to swap then just swap the data instead of the whole node. If you are not allowed to do that then you will have to figure out how to adjust all the pointers in the nodes.

Be a part of the DaniWeb community

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