小编mmm*_*eff的帖子

链接列表:冒泡排序指针(C)

我正在做大学任务.我试图在C中编写一个链表排序.我不允许交换值 - 只有指针.

这是我的排序功能:

struct node *sort_list(struct node *head) {

bool swapped ;
struct node *cur = head, *first ;

if ( head == NULL || head->next == NULL ) return head ;
else {
    do {
        swapped = false ;
        while ( cur != NULL && cur->next != NULL ){
            if (cur->value > cur->next->value){
                cur = swap_with_next( cur ) ;
                swapped = true ;
            }
            cur = cur->next ;
        }   
    } while (swapped == true) ;

}
return head …
Run Code Online (Sandbox Code Playgroud)

c pointers linked-list data-structures

4
推荐指数
1
解决办法
1402
查看次数

标签 统计

c ×1

data-structures ×1

linked-list ×1

pointers ×1