Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- */
- package lab122;
- /**
- *
- * @author JAKUB
- */
- public class Lab122 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- String tekst="aababaaaa";
- String wzorzec="ba";
- System.out.println ( "Tekst: \t\t" + tekst );
- System.out.println ( "Wzorzec: \t" + wzorzec );
- System.out.println (tekst );
- int ilosc = 0;
- for ( int i = 0; i <=tekst.length () - wzorzec.length (); ++ i )
- {
- int j = 0;
- while ( j < wzorzec.length () && tekst.charAt ( i + j ) == wzorzec.charAt ( j ) )
- {
- ++ j;
- }
- if ( j == wzorzec.length () )
- {
- System.out.print ( "^");
- ++ ilosc;
- }
- else if ( j!=wzorzec.length() )
- {
- System.out.print ( " " );
- }
- }
- System.out.println ( "\nIlość: " + ilosc + "\n" );
- }
- }
- */
- package lab12;
- import java.util.Arrays;
- import java.util.Random;
- /**
- *
- * @author Seko
- */
- public class Zadanie2
- {
- public int[] tab;
- public int[] tmp;
- public Zadanie2 ( int n )
- {
- this.tmp = new int[ n ];
- Random rand = new Random ();
- this.tab = new int[ n ];
- for ( int i = 0; i < n; ++ i )
- {
- this.tab[ i ] = rand.nextInt ( 100 );
- }
- }
- public void MergeSort ()
- {
- System.out.println ( "Przed sortowaniem:\n" + Arrays.toString ( this.tab ) );
- MergeSort ( 0, this.tab.length - 1 );
- System.out.println ( "Po sortowaniu:\n" + Arrays.toString ( this.tab ) );
- }
- private void MergeSort ( int indexPoczatkowy, int indexKoncowy )
- {
- int indexSrodek = ( indexPoczatkowy + indexKoncowy + 1 ) / 2;
- if ( indexSrodek - indexPoczatkowy > 1 )
- {
- MergeSort ( indexPoczatkowy, indexSrodek - 1 );
- }
- if ( indexKoncowy - indexSrodek > 0 )
- {
- MergeSort ( indexSrodek, indexKoncowy );
- }
- int indexLewego = indexPoczatkowy;
- int indexPrawego = indexSrodek;
- for ( int i = indexPoczatkowy; i <= indexKoncowy; ++ i )
- {
- this.tmp[ i ] = ( ( indexLewego == indexSrodek ) || ( indexPrawego <=
- indexKoncowy && this.tab[ indexLewego ] > this.tab[ indexPrawego ] ) )
- ? this.tab[ indexPrawego ++ ] : this.tab[ indexLewego ++ ];
- }
- for ( int i = indexPoczatkowy; i <= indexKoncowy; ++ i )
- {
- this.tab[ i ] = this.tmp[ i ];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement