第十章(11) 基數排序

2021-07-02 01:51:44 字數 1699 閱讀 1291

這次的經歷終於讓我嘗到了什麼叫「盡信書不如無書」!雖然以前也有過類似的經歷,但是這次的經歷實在是太深刻了啊!除錯乙個小時!!!這就是代價啊!不過這也有好處,讓我對基數排序的原理理解更深了!

(思想和**近似書上所描敘!)

#include < stdio.h >

#include < stdlib.h >

#define max_num_of_key 3  //關鍵字項數的最大值

#define radix   10  //關鍵字基數,此時是十進位制整數的基數

#define max_space  50

typedef int keystype ;

typedef struct slcell ;      //靜態鍊錶的結點型別

typedef struct sllist ;      //靜態鍊錶型別

typedef int arrtype[ radix ] ; //指標陣列型別

void initlist( sllist *l , int data[ ] , int n ) ;

void distribute( slcell *r , int i , arrtype *f , arrtype *e ) ;

void collect( slcell *r , int i , arrtype f , arrtype e ) ;

void radixsort( sllist *l ) ;

int ord( keystype key ) ;

int succ( int next ) ;

#include "radixsorting.h"

int ord( keystype key )

void distribute( slcell *r , int i , arrtype *f , arrtype *e )   //*f為頭,*e為尾 }

int succ( int next )

void collect( slcell *r , int i , arrtype f , arrtype e ) }

r[ t ].next = 0 ;        //t指向最後乙個非空子表中的最後乙個結點

}void radixsort( sllist *l )

}void initlist( sllist *l , int data[ ] , int n )

l->r[ i + 1 ].keys[ j ] = data[ i ] % radix ;

j ++ ;

l->r[ i + 1 ].next = i + 2 ;

if( l->keynum < j )

l->keynum = j ;

++ i ;

}  l->r[ l->recnum ].next = 0 ;

}void print( sllist l )

printf( " " ) ;

j = l.r[ j ].next ;}}

int main( )

;sllist l ;

initlist( &l , data , 10 ) ;

print( l ) ;

printf( "\n" ) ;

radixsort( &l ) ;

print( l ) ;

printf( "\n" ) ;

return 0 ;

}

第十章 排序 歸併排序與基數排序

2 1 對n個記錄進行歸併排序,歸併趟數的數量級是 1分 o logn o n o nlogn o n 2 2 2對n個記錄進行歸併排序,空間複雜度為 1分 o logn o n o nlogn o n 2 2 3給出關鍵字序列,下面哪個選擇是按次位優先 lsd 鏈式基數排序進行了一趟分配和收集的結...

第十章(4) 希爾排序

include using namespace std 希爾排序 shell sort 又稱 縮小增量排序 他是對插入排序類方法的改進 1.對插入排序的分析得其時間複雜度為o n n 但若待排記錄為 正序 時,其時間複雜度可提高至o n 2.在直接插入排序中,當n值很小的時候效率比較高 所以,希爾排...

第十章 SQL排序(一)

排序規則指定值的排序和比較方式,並且是intersystems sql和intersystemsiris 資料平台物件的一部分。有兩種基本排序規則 數字和字串。預設的字串排序規則是sqlupper 為每個命名空間設定此預設值。sqlupper排序規則將所有字母都轉換為大寫 出於排序的目的 並在字串的...