Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- void print(int a[],int n){
- int i;
- for(i=0;i<n;i++)
- printf("%d ",a[i]);
- printf("\n");
- }
- void insertionSort(int a[],int n){
- int i,j,t;
- for(i=0;i<n;i++){
- t=a[i];
- for(j=n;j>0&&a[j-1]>t;j--)
- a[j]=a[j-1];
- a[j]=t;
- }
- }
- void selectionSort(int a[],int n){
- int i,j,min,t;
- for(i=0;i<n-1;i++){
- min=i;
- for(j=i+1;j<n;j++){
- if(a[j]>a[min])min=j;
- }
- t=a[i];
- a[i]=a[min];
- a[min]=t;
- }
- }
- void bubbleSort(int a[],int n){
- int i,j,t;
- for(i=0;i<n;i++)
- for(j=i+1;j<n;j++)
- if(a[i]>a[j]){
- t=a[i];
- a[i]=a[j];
- a[j]=t;
- }
- }
- void shellSort(int a[],int n){
- int i,j,k,t;
- for(i=n/2;i>0;i/=2)
- for(j=i;j<n;j++)
- for(k=j-i;k>=0;k=k-i)
- if(a[k+i]<a[k]){
- t=a[k+i];
- a[k+i]=a[k];
- a[k]=t;
- }
- }
- /*void mergeSort(){}
- void heapSort(){}
- void quickSort(int a[],int n){}
- void quick3Sort(int a[],int n){}*/
- int main(){
- char ime[20];
- int i,n,b,a[20],x=1;
- srand(time(NULL));
- b=rand()%100;
- printf("Unesite svoje ime: ");
- scanf("%s",ime);
- n=strlen(ime);
- printf("Pokusajte pogoditi broj izmedju 0 i 100 imate %d pokusaja!\n",n);
- for(i=0;i<n;i++){
- scanf("%d",&a[i]);
- if(a[i]<b)printf("Slucajni broj je veci od unesenog!\n");
- if(a[i]>b)printf("Slucajni broj je manji od unesenog!\n");
- if(a[i]==b){printf("Svaka cast!Pogodili ste slucajan broj!\n");n=++i;x=0;break;}
- }
- if(x)printf("Tacan broj je %d\n",b);
- printf("Brojevi koje ste redom unosili su:\n");
- print(a,n);
- printf("\nRastuci BubbleSort:\n");
- bubbleSort(a,n);
- print(a,n);
- printf("\nOpadjuci SelectionSort:\n");
- selectionSort(a,n);
- print(a,n);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement