Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define N 10
- #define M 15
- int main()
- {
- int pin1[N], pin2[M];
- int j, i, k, num, potition, temp, check;
- // 1ST MATRIX
- printf("INITIAL MATRIX\n");
- // edw gemizeis ton pinaka enw soy leei na mhn to kaneis
- /*
- for(i=0;i<N;i++){
- pin1[i] = rand()%10; specific seed to test matrix
- }
- for(i=0;i<N;i++){
- printf("Potition: %d: %d\n", i, pin1[i]);
- }
- */
- // edw kanw mia arxikopoihsh gia ta matia tou kosmou
- for(i = 0; i < N; i++){
- pin1[i] = 0;
- }
- printf("SORTED MATRIX\n");
- for(i=0;i<N;i++){
- // edw pairneis ena tyxaio ari8mo opws 8es
- num = rand()%10;
- // edw allazes to num kai exanes ton tyxaio ari8mo
- //num = pin1[i];
- //potition = i;
- // o elegxos pou sou elega na kaneis apla ton alla3a epeidh eixa kanei la8os
- check = 0;
- for(j=0; j<i;j++){
- if(pin1[j] == num){
- i--;
- check = 1;
- break;
- }
- // what is this?
- //pin1[potition] = num;
- }
- if(check == 1){
- continue;
- }
- // auth h if den xreiazetai
- //if(pin1[potition-1] >= num){
- //den xreiazetai na kaneis insertion sort afou esu ftiaxneis ton pinaka
- //oi sorting algorithms einai ftiagmenoi gia hdh etoimous pinakes
- /*
- while((pin1[potition-1] >= num) && (potition - 1 >= 0)){
- edw xaneis stoixeia epeidh den kratas kapou thn timh tou pin[position]
- pin1[potition] = pin1[potition-1];
- potition = potition - 1;
- }
- */
- // potition = i;
- for(j = 0; j < i; j++){
- if(pin1[j] > num){
- for(k = i - 1; k >= j; k--){
- pin1[k + 1] = pin1[k];
- }
- break;
- }
- }
- //}
- //else if(pin1[potition-1] == num){
- //break;
- // }
- pin1[j] = num;
- }
- for(i=0;i<N;i++){
- printf("Potition: %d: %d\n", i, pin1[i]);
- }
- // 2ND MATRIX
- // printf("2ND MATRIX\n");
- //for(i=0;i<M;i++){
- //pin2[i] = rand()%(900) + 100;
- //}
- //(i=0;i<M;i++){
- //printf("Number %d: %d\n", i+1, pin2[i]);
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement