int main(int argc, char *argv[]) { if (argc > 1) { if (!(strcmp(argv[1], "-h"))) Help(); } FILE *in_file_1, *in_file_2, *out_file; in_file_1 = Open_file("file1", "wb"); in_file_2 = Open_file("file2", "wb"); out_file = Open_file("file3", "wb"); puts("Enter the number in the first file in ascending:"); Create_file(in_file_1); puts("Enter the number in the second file in ascending:"); Create_file(in_file_2); fclose(in_file_1); fclose(in_file_2); in_file_1 = Open_file("file1", "rb"); in_file_2 = Open_file("file2", "rb"); Sorting(in_file_1, in_file_2, out_file); fclose(in_file_1); fclose(in_file_2); fclose(out_file); out_file = Open_file("file3", "rb"); puts("THE OUTPUT FILE:"); Viewing_file(out_file); return 0; }
//closest to zero sum void minAbsSumPair(int A[], int n) { /* Array should have at least two elements*/ if(n < 2) { cout<<"Invalid Input"; return; } Sorting *obj = &Sorting(); obj->SetArray(A, n); obj->InsertionSort(); // left and right index variables int l = 0, r = n-1; int sum,minsum=A[r]; int min_l,min_r; while(l<r) { sum=A[l]+A[r]; if(abs (minsum) > abs(sum)) { minsum=sum; min_l = l; min_r = r; } if(sum >= 0) r--; else l++; } cout<<"min sum is "<<A[min_l]<< " + " <<A[min_r]<<" = "<< minsum; }
void SortFooDemo() { static const int size = 15; int *int_arr; char *str; int str_size = 0; int_arr = new int[size]; str = new char[size]; srand(time(NULL)); for (int i = 0; i < size; i++) { int_arr[i] = rand() % 150 + 0; } cout << "Enter string: "; cin.getline(str, size); cin.clear(); cin.sync(); system("pause"); system("cls"); // INT cout << "Integer digits array before sort: " << endl; for (int i = 0; i < size; i++) { cout << int_arr[i] << " "; } Sorting(int_arr, size); cout << endl << "Integer digits array after sort: " << endl; for (int i = 0; i < size; i++) { cout << int_arr[i] << " "; } cout << endl << endl; // CHAR str_size = strlen(str); cout << "Char digits array before sort: " << endl; for (int i = 0; i < str_size; i++) { cout << str[i]; } Sorting(str, str_size); cout << endl << "Char array after sort: " << endl; for (int i = 0; i < str_size; i++) { cout << str[i]; } cout << endl << endl; delete int_arr; delete str; return; }
struct node* Sorting(struct node* temp1, struct node* temp2) { struct node* ans = NULL; if (temp1 == NULL) return(temp2); else if (temp2 == NULL) return(temp1); if (temp1->num <= temp2->num) { ans = temp1; ans->next = Sorting(temp1->next, temp2); } else { ans = temp2; ans->next = Sorting(temp1, temp2->next); } return ans; }
bool CheckDuplicacy(int *Arr,int len) { Sorting *obj = &Sorting(); obj->SetArray(Arr, len); obj->InsertionSort(); for (int i=0;i<len;i++) { if (Arr[i]=Arr[i+1]) return true; } return false; }
struct node * merge2LinkedLists(struct node *head1, struct node *head2) { struct node* temp1 = head1; struct node* temp2 = head2; if ((temp1 == NULL) && (temp2 != NULL)) { return head2; } else if ((temp1 != NULL) && (temp2 == NULL)) { return head1; } else if ((temp1 != NULL) && (temp2!=NULL)) { Sorting(temp1, temp2); } else return NULL; }
int main() { int t, row, col, i, j, count = 0; unsigned char **Room; unsigned char temp; FILE *fp; fp = fopen("input.txt", "r"); if (fp == NULL) return 0; /* start FILE IO */ fscanf(fp, "%d", &t); /* read Data Number */ while (t--) { fscanf(fp, "%d %d", &col, &row); /* read Data */ Room = (unsigned char**)malloc(sizeof(unsigned char*)*row); /* read Room data */ for (i = 0; i < row; i++) Room[i] = (unsigned char*)malloc(sizeof(unsigned char)*(col)); for (i = 0; i < row; i++) { for (j = 0; j < col; j++) { fscanf(fp, "%c", &temp); while ((temp != '.') && (temp != '+')) fscanf(fp, "%c", &temp); Room[i][j] = temp; } } for (i = 1; i < row-1; i++) for (j = 0; j < col; j++) if (Room[i][j] == '.') count += floodFill(Room, i, j, '.', '+', &count); /* figure out result */ printf("%d\n", count); /* print output */ Sorting(roomSIZE, 0, count); for (i = 0; i < count; i++) printf("%d ", roomSIZE[i]); printf("\n"); for (i = 0; i < row; i++) /* initialize Room memory */ { free(Room[i]); Room[i] = NULL; } free(Room); Room = NULL; for (i = 0; i < count; i++) roomSIZE[i] = 0; /* initialize roomsize */ count = 0; /* initialize room counter */ } fclose(fp); /* close FILE IO */ return 1; }
int hasArrayTwoCandidates(int A[], int size, int k) { Sorting *obj = &Sorting(); obj->SetArray(A, size); obj->InsertionSort(); int left=0; int right=size-1; while(left<right) { if (A[left]+A[right] == k ) { cout<<"number are "<<A[left] <<" ,"<<A[right]<<endl; return 1; } if ( A[left]+A[right] < k) left++; else right-- ; } return 0; }
int MaxOccurance(int *Arr,int len) { int currentcount=0,maxc=0; Sorting *obj = &Sorting(); obj->SetArray(Arr, len); obj->InsertionSort(); int currentcandidate=Arr[0],maxcandidate = Arr[0]; for(int i=0;i<len;i++) { if(Arr[i]==currentcandidate) currentcount++; else { currentcandidate=Arr[i]; currentcount=1; } if(currentcount>maxc) { maxc=currentcount; maxcandidate=currentcandidate; } } return maxcandidate; }
void KeyFrame::Summary() { FILE *IN_FILE; long long tmp1,tmp2; int numfrm, frmnum; unsigned char* temp1 = new unsigned char[Width*Height*3]; unsigned char* temp2 = new unsigned char[Width*Height*3]; unsigned char* temp3 = new unsigned char[Width*Height*3]; double* energy = new double[NumofFrame]; for(int k = 0; k < NumofFrame; k++){ energy[k] = 0; } IN_FILE = fopen(VideoPath, "rb"); /*tmp1 = ftell(IN_FILE); fseek(IN_FILE, 0L, SEEK_END); tmp2 = ftell(IN_FILE); numfrm = (tmp2 - tmp1) / (Width*Height*3*sizeof(unsigned char)); fseek(IN_FILE, 0L, SEEK_SET); tmp1 = _ftelli64(IN_FILE); _fseeki64(IN_FILE, 0L, SEEK_END); tmp2 = _ftelli64(IN_FILE); numfrm = (tmp2 - tmp1) / (Width*Height*3*sizeof(unsigned char)); _fseeki64(IN_FILE, 0L, SEEK_SET);*/ SummaryData = new int[NumofFrame]; numfrm = 15000; //summary //copy data for 3 frame frmnum = 0; while(frmnum < numfrm) { if(frmnum == 0) { fread(temp1, sizeof(unsigned char), Width*Height*3, IN_FILE); memcpy(temp2, temp1, sizeof(unsigned char)*Width*Height*3); fread(temp3, sizeof(unsigned char), Width*Height*3, IN_FILE); } else if(frmnum == numfrm - 1) { memcpy(temp1, temp2, sizeof(unsigned char)*Width*Height*3); memcpy(temp2, temp3, sizeof(unsigned char)*Width*Height*3); } else { memcpy(temp1, temp2, sizeof(unsigned char)*Width*Height*3); memcpy(temp2, temp3, sizeof(unsigned char)*Width*Height*3); fread(temp3, sizeof(unsigned char), Width*Height*3, IN_FILE); } //compute energy for frame EnergyComputation(temp1, temp2, temp3, frmnum, SummaryData, energy, NumofFrame); //go to next frame frmnum++; } Sorting(SummaryData, NumofFrame); delete[]temp1; delete[]temp2; delete[]temp3; }
QueryResultsNode::Sorting QueryResultsNode::sorting() const { return Sorting(0, Qt::AscendingOrder); }