Java



           

Сортировка таблицы средствами JavaScript - часть 8


return retStr; }

function weight( str ) { var retArray = [];

for( var i = 0; i < str.length; i++ ) { var tmp = str.charCodeAt( i ); if( tmp >= 1046 && tmp < 1078 ) tmp++; else if( tmp == 1025 ) tmp = 1046; else if( tmp >= 1078 ) tmp++; else if( tmp == 1105 ) tmp = 1078; retArray[ i ] = tmp; }

return retArray; }

function fillArray( years, books, authors ) { authors = upCs( authors, " " ); authors = upCs( authors, "-" ); books = upCs( books, "" );

this.years = years; this.yweight = weight( years ); this.books = books; this.bweight = weight( books ); this.authors = authors; this.aweight = weight( authors ); }

function isLow( low, high, type ) { var len1 = low[ type ].length; var len2 = high[ type ].length; var length = len1 < len2 ? len1 : len2;

for( var i = 0; i < length; i++ ) { var str1 = low[ type ][ i ]; var str2 = high[ type ][ i ]; if( str1 < str2 ) return true; if( str1 > str2 ) return false; }

if( len1 < len2 ) return true; return false; }

function quickSort( l, h, type ) { var low = l; var high = h; var rt = eval( "txt[ " + Math.round( ( l + h ) / 2 ) + " ]" ); var middle = new fillArray( rt.years, rt.books, rt.authors );

do {

while( isLow( eval( "txt[ " + low + " ]" ), middle, type ) ) low++;

while( isLow( middle, eval( "txt[ " + high + " ]" ), type ) ) high--;

if( low <= high ) { var temp = txt[ low ]; txt[ low++ ] = txt[ high ] txt[ high-- ] = temp; } } while( low <= high );

if( l < high ) quickSort( l, high, type ); if( low < h ) quickSort( low, h, type ); }

txt[ 0 ] = new fillArray( "1959", "фрейд", "сартр жан-поль" ); txt[ 1 ] = new fillArray( "1940", "подростки", "сэлинджер джером" ); txt[ 2 ] = new fillArray( "1946", "пена дней", "виан борис" ); txt[ 3 ] = new fillArray( "1948", "осадное положение", "камю альбер" ); txt[ 4 ] = new fillArray( "1899", "об иноческой жизни", "рильке райнер мария" ); txt[ 5 ] = new fillArray( "1849", "аннабель Ли", "по эдгар" ); txt[ 6 ] = new fillArray( "1917", "дагон", "лавкрафт говард" ); txt[ 7 ] = new fillArray( "1915", "процесс", "кафка франц" ); txt[ 8 ] = new fillArray( "1989", "египет Рамсесов", "монтэ пьер" ); txt[ 9 ] = new fillArray( "1932", "мастер и Маргарита", "булгаков михаил" );




Содержание  Назад  Вперед