void inserare(Arb* arb,int x) { Arb nou; if ((*arb)==NULL) { (*arb)=(Nod*)malloc(sizeof(Nod)); (**arb).val=x; (**arb).st=NULL; (**arb).dr=NULL; } else { if ((**arb).val==x) { //printf("Valoarea deja exista"); } else { if ((**arb).val>x) { if ((**arb).st==NULL) { nou=(Nod*)malloc(sizeof(Nod)); (*nou).val=x; (**arb).st=nou; (*((**arb).st)).st=NULL; (*((**arb).st)).dr=NULL; } else { inserare(&((**arb).st),x); } } else { if ((**arb).dr==NULL) { nou=(Nod*)malloc(sizeof(Nod)); (*nou).val=x; (**arb).dr=nou; (*((**arb).dr)).st=NULL; (*((**arb).dr)).dr=NULL; } else { inserare(&((**arb).dr),x); } } } } }
void constructie(radix*rad, char*cuv, int index) { int i; for (i = index; i < strlen(cuv); i++) { if (i == strlen(cuv) - 1) { rad->flag = true; } inserare(rad, cuv[i]); rad = (rad->next)[rad->nr_fii - 1]; } }
void reply_c(int sockfd, char *sir){ t_char bl; sockfdex = sockfd; bz = gdbm_open("baza.db", 512, GDBM_WRCREAT, 0600, 0); if(is_command(sir, &bl)){ switch (bl.c) { case 'I' : sterg();break; case 'i' : inserare(bl.cv, bl.ex);break; case 's' : stergc(bl.cv, bl.ex);break; case 'c' : exista(bl.cv);break; case 'e' : explic(bl.cv, bl.ex);break; case 'l' : afisez(); case 'q' : break; default : smsg("\nInvalid command\n"); } } else smsg("\nInvalid command\n"); gdbm_close(bz); }
int main() { Arb arb,gas; int x,i; arb=NULL; srand(time(NULL)); for (i=1;i<30;i++) { x=rand(); x=x%30; inserare(&arb,x); } //inordine(arb,0); //printf("\n\n\n"); gas=find(arb,x); if (gas!=NULL) printf("%d",(*gas).val); //preordine(arb,0); sterge(&arb,5); //preordine(arb,0); return 0; }
int main(int argc, char *argv[]) { char c,inf; cap=NULL; do { printf("1. Introducere caracter in coada.\n"); printf("2. Scoatere caracter din coada.\n"); printf("3. Afisare coada.\n"); printf("4. Golire coada.\n"); printf("Esc - Parasirea programului\n"); spati(); c=getch(); switch(c) { case '1': printf("Dati un caracter: "); inf=getche(); if(!inserare(inf)) printf("\nMemorie insuficienta!"); else printf("\nAm introdus: %c",inf); spati(); printf("Apasati orice tasta...\n\n\n"); break; case '2': if(!scoatere(&inf)) printf("Stiva goala!"); else printf("Am scos: %c",inf); spati(); printf("Apasati orice tasta...\n\n\n"); break; case '3': printf("Stiva contine: "); afisare(); spati(); printf("Apasati orice tasta...\n\n\n"); break; case '4': golirecoada(); printf("Am golit stiva!"); spati(); printf("Apasati orice tasta...\n\n\n"); break; case 27: printf("Apasati o tasta pt. a iesi!"); break; default: printf("Apasati 1,2,3,4 sau Escape"); spati(); } getch(); } while (c!=27); golirecoada(); return 0; }
void menuFunction(KdTree* myKdTree) { FILE *fp; fp=fopen("buhu.txt","r+"); int xAxis,yAxis;//Build Tree int axis=0,parentAxis=1,range; int xClosePoint,yClosePoint;//Search float currentBest; int menu=0,menuOption;//Menu do{ puts("Choose one of the following:"); puts("1.Build from file"); puts("2.Display"); puts("3.Insert"); puts("4.Closest point search"); puts("5.Range Querry"); puts("6.N closest points"); puts("7.Exit"); scanf("%d",&menuOption); char response; switch(menuOption) { case 1: { while(feof(fp)==NULL) { fscanf(fp,"%d",&xAxis); fscanf(fp,"%d",&yAxis); myKdTree=inserare( myKdTree,xAxis,yAxis,parentAxis); } break; } case 2: { listare(myKdTree,0); break; } case 3: { puts("Dati x:"); scanf("%d",&xAxis); puts("Dati y:"); scanf("%d",&yAxis); myKdTree=inserare( myKdTree,xAxis,yAxis,parentAxis); break; } case 4: { currentBest=infinity; puts("Give random number y/n?"); scanf(" %c", &response); if(121 == response) { randomGeneratorPoint(xAxis,yAxis); } else { puts("Give searched point! \n");//Read Coordinates puts("Give the x axis: \n"); scanf("%d",&xAxis); puts("Give the y axis: \n"); puts("Dati y:"); scanf("%d",&yAxis); } find_closest(myKdTree,myKdTree,xAxis,yAxis,currentBest,axis,xClosePoint,yClosePoint);//Use efficient search printf("\n Closest point using efficient methode is :",currentBest); printf("%d ",xClosePoint); printf("%d\n",yClosePoint); currentBest=infinity;//Set current distance to max hard_work(myKdTree,xAxis,yAxis,xClosePoint,yClosePoint,currentBest); printf("\n Closest point using hardcore methode is :",currentBest);//Use shovel search printf("%d ",xClosePoint); printf("%d\n",yClosePoint); break; } case 5: { puts("Give random number and range y/n?"); scanf(" %c",&response); if(121 == response) { randomGeneratorPoint(xAxis,yAxis); range=rand()%100+1; } else { puts("Give querry point! \n");//Read Coordinates and range puts("Give the x axis: \n"); scanf("%d",&xAxis); puts("Give the y axis: \n"); scanf("%d",&yAxis); puts("Give range: \n"); scanf("%d",&range); } puts("\nThe points inside the range are: "); range_Querry(myKdTree,myKdTree,xAxis,yAxis,range);//Use efficient search puts("\nThe points inside the range using hard work methode are: "); hard_Work_Querry(myKdTree,xAxis,yAxis,range); break; } case 6: { currentBest=infinity; int points_Number; int contor=0; puts("Give random number y/n?"); scanf(" %c", &response); if(121 == response) { randomGeneratorPoint(xAxis,yAxis); points_Number=rand()%14+1; } else { puts("Give searched point! \n");//Read Coordinates puts("Give the x axis: \n"); scanf("%d",&xAxis); puts("Give the y axis: \n"); puts("Dati y:"); scanf("%d",&yAxis); puts("Give the number n for the closest points: \n"); scanf("%d",&points_Number); } std::vector<PointContainer>closest_Distances(points_Number); find_closest_Points(myKdTree,myKdTree, xAxis, yAxis,currentBest,axis,closest_Distances,points_Number,contor);//Use efficient search puts("\nClosest n points are: "); for(int i=0;i<points_Number;i++) printf(" %d %d ",closest_Distances[i].x,closest_Distances[i].y); currentBest=infinity;//Set current distance to max contor=0; hard_work_closest(myKdTree,xAxis,yAxis,currentBest,closest_Distances,points_Number,contor); puts("Closest n points using hard work are: \n"); for(int i=0;i<points_Number;i++) printf(" %d %d ",closest_Distances[i].x,closest_Distances[i].y); break; puts(""); } case 7: { return; } } }while(menu!=7); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static int ok = 0; static int nr_fis_intrare = 0; static int nr_fis_iesire = 0; switch (msg) { case WM_CREATE: { //text static 1 HWND statik = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE|SS_CENTER, 60, 10, 300, 200, hwnd, NULL, NULL, NULL); SetWindowText( statik, "Introduceti textul pentru prelucrare!!" ); // //text static nr2 HWND statik2 = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE|SS_CENTER, 60, 260, 300, 200, hwnd, NULL, NULL, NULL); SetWindowText( statik2, "Arborele radix corespunzator este:" ); //caseta text nr 1 HFONT hfDefault; hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 0, 40, 400, 200, hwnd, NULL, GetModuleHandle(NULL), NULL); if (hEdit == NULL) MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR); //caseta text nr 2 HFONT hfDefault2; hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 0, 280, 400, 200, hwnd, NULL, GetModuleHandle(NULL), NULL); if (hEdit == NULL) MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR); //caseta taext 3 HFONT hfDefault3; hEdit3 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 410, 350, 200, 100, hwnd, NULL, GetModuleHandle(NULL), NULL); if (hEdit == NULL) MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR); //buton 1 CreateWindow("BUTTON", "Afisare arbore", WS_BORDER | WS_CHILD | WS_VISIBLE, 410, 300, 250, 50, hwnd, (HMENU)Buton_Afisare, NULL, NULL); // //buton 2 CreateWindow("BUTTON", "Apasati pentru a prelucra textul!", WS_BORDER | WS_CHILD | WS_VISIBLE, 410, 50, 250, 50, hwnd, (HMENU)Buton_prelucrare, NULL, NULL); LoadTextFileToEdit(hEdit,"f.txt"); } break; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_FILE_OPEN: { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if (GetOpenFileName(&ofn)) { // Do something usefull with the filename stored in szFileName MessageBox(hwnd, szFileName, "Ati ales", MB_OK | MB_ICONEXCLAMATION); static char text[100]; LoadTextFileToEdit(hEdit, szFileName); } } break; case ID_FILE_SAVE: { int val=0; val = GetWindowText(hEdit, &textSaved[0], 20000); MessageBox(hwnd, textSaved, "Salvati urmatorul text:", MB_OK | MB_ICONEXCLAMATION); OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if (GetOpenFileName(&ofn)) { // Do something usefull with the filename stored in szFileName MessageBox(hwnd, szFileName, "Text Salvat in:", MB_OK | MB_ICONEXCLAMATION); } SaveTextFileFromEdit(hEdit, szFileName); } break; case ID_START: { } break; case Buton_prelucrare: { int k = 1; SetWindowText(hEdit2, ""); if (SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0) == 0) // then field is empty { MessageBox(hwnd, "Nu ati introdus text!", "Atentionare!", MB_OK | MB_ICONERROR); SetWindowText(hEdit3, ""); //golire textbox3 FILE*f = fopen("f.txt", "wt"); fputs("Introduceti text!", f); LoadTextFileToEdit(hEdit, "fis.txt"); fclose(f); } else { SaveTextFileFromEdit(hEdit, "fis.txt"); char cuv[100]; inserare(rad, '*'); FILE*fis = fopen("fis.txt", "rt"); FILE*fis2; while (!feof(fis)) { fscanf(fis, "%s", cuv); functie(cuv, rad); } fseek(fis, 0, 0); nr_fis_intrare = nr_caractere(fis); fclose(fis); fis2 = fopen("f.txt", "wt"); afisare(fis2, 0, rad); fclose(fis2); fis2 = fopen("f.txt", "rt"); fseek(fis, 0, 0); nr_fis_iesire = nr_caractere(fis2); fclose(fis2); stergere(rad); rad = NULL; ok = 1; MessageBox(hwnd, "Textul a fost prelucrat cu succes!", "Atentionare!", MB_OK | MB_ICONINFORMATION); } } break; case Buton_Afisare: { if (ok == 1) { ok = 0; MessageBox(hwnd, "Textul a fost transformat cu succes!!", "Atentionare!", MB_OK | MB_ICONINFORMATION); LoadTextFileToEdit(hEdit2, "f.txt"); // FILE*fis = fopen("f.txt", "wt"); fprintf(fis, "Numar initial:%d\n", nr_fis_intrare); fprintf(fis, "Numar comprimat:%d\n", nr_fis_iesire); int x = 100 - ((nr_fis_iesire*100/nr_fis_intrare)); fprintf(fis, "Procentul de eficienta: %d", x); fprintf(fis,"%c", '%'); fclose(fis); LoadTextFileToEdit(hEdit3,"f.txt"); fis = fopen("f.txt", "wt"); fclose(fis); } else { MessageBox(hwnd, "Textul nu a fost prelucrat anterior!!", "Atentionare!", MB_OK | MB_ICONSTOP); SetWindowText(hEdit3, ""); } FILE*fis = fopen("f.txt", "wt"); fputs("Introduceti text!", fis); LoadTextFileToEdit(hEdit, "fis.txt"); fclose(fis); fis = fopen("fis.txt", "wt"); fclose(fis); } break; case ID_CLEAR: { SetWindowText(hEdit,""); SetWindowText(hEdit2, ""); SetWindowText(hEdit3, ""); } break; } break; case WM_SIZE: { HWND hEdit; RECT rcClient; GetClientRect(hwnd, &rcClient); hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT); SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER); } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }