├── 2024-2025 ├── SeriaCSol │ ├── SeriaCProj │ │ ├── HeapKeys.txt │ │ ├── headers.h │ │ ├── fImpl.c │ │ ├── Graf.txt │ │ ├── Studenti.txt │ │ ├── fApp.c │ │ ├── SeriaCProj.vcxproj.user │ │ ├── 01_MemorieVariabilec.c │ │ ├── 04_Preprocesare_1.c │ │ ├── 03_Functii.c │ │ ├── 03_Pointeri.c │ │ ├── SeriaCProj.vcxproj.filters │ │ ├── 05_ListeDuble.c │ │ ├── 04_ListeSimple.c │ │ ├── 12_Arbori.c │ │ ├── 13_AVL.c │ │ └── 10_StructHeap.c │ └── SeriaCSol.sln ├── SeriaDSol │ ├── SeriaDProj │ │ ├── HeapKeys.txt │ │ ├── headers.h │ │ ├── f_implementare.c │ │ ├── Graf.txt │ │ ├── Studenti.txt │ │ ├── SeriaDProj.vcxproj.user │ │ ├── app.c │ │ ├── 04_Preprocesare.c │ │ ├── 01_MemorieVariabile.c │ │ ├── SeriaDProj.vcxproj.filters │ │ ├── 03_Functii.c │ │ ├── 05_ListeDuble.c │ │ ├── 05_ListeSimple.c │ │ ├── 13_AVL.c │ │ ├── 11_ArboriO.c │ │ └── 08_Heap.c │ └── SeriaDSol.sln ├── Grupa1055Sol │ ├── Grupa1055Proj │ │ ├── Graf.txt │ │ ├── Grupa1055Proj.vcxproj.user │ │ ├── CarduriBancare.txt │ │ ├── Grupa1055Proj.vcxproj.filters │ │ ├── 01_TipuriDate.c │ │ ├── 02_Masive.c │ │ ├── 04_ListaSimple.c │ │ ├── 10_Struct_Heap.c │ │ ├── 05_ListeDuble.c │ │ └── 14_Graf.c │ └── Grupa1055Sol.sln ├── Grupa1058Sol │ ├── Grupa1058Proj │ │ ├── Graf.txt │ │ ├── Grupa1058Proj.vcxproj.user │ │ ├── CarduriBancare.txt │ │ ├── Grupa1058Proj.vcxproj.filters │ │ ├── 01_TipuriDate.c │ │ ├── 10_StructHeap.c │ │ ├── 03_Structuri.c │ │ ├── 04_ListeSimple.c │ │ ├── 05_ListeDuble.c │ │ └── 14_Graf_lst.c │ └── Grupa1058Sol.sln ├── Grupa1059Sol │ ├── Grupa1059Proj │ │ ├── Graf.txt │ │ ├── Grupa1059Proj.vcxproj.user │ │ ├── CarduriBancare.txt │ │ ├── Grupa1059Proj.vcxproj.filters │ │ ├── 01_TipuriDate.c │ │ ├── 02_Masive.c │ │ ├── 04_ListeSimple.c │ │ ├── 11_ArbBin.c │ │ ├── 05_ListeDuble.c │ │ ├── 10_Struct_MaxHeap.c │ │ └── 14_Graf.c │ └── Grupa1059Sol.sln ├── Grupa1062Sol │ ├── Grupa1062Proj │ │ ├── Graf.txt │ │ ├── Grupa1062Proj.vcxproj.user │ │ ├── CarduriBancare.txt │ │ ├── Grupa1062Proj.vcxproj.filters │ │ ├── 01_TipuriDate.c │ │ ├── 03_Structuri.c │ │ ├── 10_StructHeapc.c │ │ ├── 04_ListeSimple.c │ │ └── 05_ListeDuble.c │ └── Grupa1062Sol.sln ├── Grupa1075Sol │ ├── Grupa1075Proj │ │ ├── Graph.txt │ │ ├── Grupa1075Proj.vcxproj.user │ │ ├── CardData.txt │ │ ├── Grupa1075Proj.vcxproj.filters │ │ ├── 01_DataTypes.c │ │ ├── 03_Structures.c │ │ ├── 06_DoubleLists.c │ │ └── 04_SimpleLists.c │ └── Grupa1075Sol.sln └── Grupa1076Sol │ ├── Grupa1076Proj │ ├── Graph.txt │ ├── Grupa1076Proj.vcxproj.user │ ├── CardData.txt │ ├── Grupa1076Proj.vcxproj.filters │ ├── 01_DataTypes.c │ ├── 03_Structures.c │ ├── 04_SimpleList.c │ └── 05_DoubleList.c │ └── Grupa1076Sol.sln └── README.md /2024-2025/SeriaCSol/SeriaCProj/HeapKeys.txt: -------------------------------------------------------------------------------- 1 | 28 24 8 12 23 2 3 7 9 17 -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/HeapKeys.txt: -------------------------------------------------------------------------------- 1 | 28 24 8 12 23 2 3 7 9 17 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # structuri 2 | Suport cod sursa Structuri de Date 3 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/headers.h: -------------------------------------------------------------------------------- 1 | extern int i; 2 | 3 | void f(); 4 | -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/headers.h: -------------------------------------------------------------------------------- 1 | 2 | extern int i; 3 | 4 | void f(); 5 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/fImpl.c: -------------------------------------------------------------------------------- 1 | #include "headers.h" 2 | 3 | void f() { 4 | i++; 5 | } 6 | -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/f_implementare.c: -------------------------------------------------------------------------------- 1 | #include "headers.h" 2 | 3 | void f() { 4 | i++; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/Graf.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 1 2 3 | 1 4 4 | 2 3 5 | 2 8 6 | 3 4 7 | 3 7 8 | 4 5 9 | 5 7 10 | 6 7 11 | 7 8 12 | 5 6 -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/Graf.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 1 2 3 | 1 4 4 | 2 3 5 | 2 8 6 | 3 4 7 | 3 7 8 | 4 5 9 | 5 7 10 | 6 7 11 | 7 8 12 | 5 6 -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/Graf.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 1 2 3 | 1 4 4 | 2 3 5 | 2 8 6 | 3 4 7 | 3 7 8 | 4 5 9 | 5 7 10 | 6 7 11 | 7 8 12 | 5 6 -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/Graf.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 1 2 3 | 1 4 4 | 2 3 5 | 2 8 6 | 3 4 7 | 3 7 8 | 4 5 9 | 5 7 10 | 6 7 11 | 7 8 12 | 5 6 -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/Graf.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 1 2 3 | 1 4 4 | 2 3 5 | 2 8 6 | 3 4 7 | 3 7 8 | 4 5 9 | 5 7 10 | 6 7 11 | 7 8 12 | 5 6 -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Proj/Graf.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 1 2 3 | 1 4 4 | 2 3 5 | 2 8 6 | 3 4 7 | 3 7 8 | 4 5 9 | 5 7 10 | 6 7 11 | 7 8 12 | 5 6 -------------------------------------------------------------------------------- /2024-2025/Grupa1075Sol/Grupa1075Proj/Graph.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 1 2 3 | 1 4 4 | 2 3 5 | 2 8 6 | 3 4 7 | 3 7 8 | 4 5 9 | 5 7 10 | 6 7 11 | 7 8 12 | 5 6 -------------------------------------------------------------------------------- /2024-2025/Grupa1076Sol/Grupa1076Proj/Graph.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 1 2 3 | 1 4 4 | 2 3 5 | 2 8 6 | 3 4 7 | 3 7 8 | 4 5 9 | 5 7 10 | 6 7 11 | 7 8 12 | 5 6 -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/Studenti.txt: -------------------------------------------------------------------------------- 1 | 43,Vasilescu Mihai,8.45 2 | 12,Ionescu George,7.64 3 | 374,Popescu Gigel,9.33 4 | 1,Ionescu Pavel,8.80 5 | 13,Georgescu Alexandru,6.57 6 | 453,Gigel opescuP,9.33 7 | -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/Studenti.txt: -------------------------------------------------------------------------------- 1 | 43,Vasilescu Mihai,8.45 2 | 12,Ionescu George,7.64 3 | 374,Popescu Gigel,9.33 4 | 1,Ionescu Pavel,8.80 5 | 13,Georgescu Alexandru,6.57 6 | 453,Gigel opescuP,9.33 7 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/fApp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int i; 5 | 6 | int main() { 7 | i = 3; 8 | 9 | f(); 10 | printf("%d\n", i); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/SeriaCProj.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/SeriaDProj.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/Grupa1055Proj.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/Grupa1058Proj.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/Grupa1059Proj.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Proj/Grupa1062Proj.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2024-2025/Grupa1075Sol/Grupa1075Proj/Grupa1075Proj.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2024-2025/Grupa1076Sol/Grupa1076Proj/Grupa1076Proj.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/app.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int i; 5 | 6 | int main() { 7 | i = 3; 8 | 9 | f(); 10 | printf("%d\n", i); 11 | f(); 12 | printf("%d\n", i); 13 | 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/CarduriBancare.txt: -------------------------------------------------------------------------------- 1 | 6413889977660001,Vasilescu Mircea,10/28,1157.97,RON 2 | 6413889977874325,Popescu Georgian,05/27,168.07,RON 3 | 6413419977871105,Ionescu Traian,8/28,98.62,RON 4 | 6413419977871103,Ionescu Alexandru Dorian,9/27,101.22,RON 5 | -------------------------------------------------------------------------------- /2024-2025/Grupa1075Sol/Grupa1075Proj/CardData.txt: -------------------------------------------------------------------------------- 1 | Popescu Marian Alexandru,6523000099998765,10/28,BCR,1986.94 2 | Ionescu Virgil,6234999912349807,7/26,Unicredit,105.08 3 | Vasilescu Mihai George,6154888855556531,1/26,Citi,87.54 4 | Vasilescu Ioan,6154888855556551,2/27,BT,34.54 5 | -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Proj/CarduriBancare.txt: -------------------------------------------------------------------------------- 1 | 6453000099991010;Ionescu Vasile Marian;10/2025;101.67;RON 2 | 6463010033999901;Popescu Alexandru;04/2026;874.02;RON 3 | 6457897399228002;Vasilescu George;07/2026;3.09;EUR 4 | 6457897399228012;Georgescu Cosmin;11/2026;1.07;RON 5 | -------------------------------------------------------------------------------- /2024-2025/Grupa1076Sol/Grupa1076Proj/CardData.txt: -------------------------------------------------------------------------------- 1 | 6523999900001234,10/26,Popescu Virgil Marian,Romanian Leu,199.87 2 | 6542777788881908,04/25,Ionescu Alexandru,Euro,89.62 3 | 6523667711220099,07/26,Vasilescu Mihai George,Romanian Leu,0.76 4 | 6523667711220098,07/26,Georgescu Marian,Euro,0.76 5 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/01_MemorieVariabilec.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | 6 | register int vreg; 7 | int d; 8 | 9 | d = 8; 10 | vreg = d; 11 | 12 | printf("vreg = %d\n", vreg); 13 | 14 | __asm 15 | { 16 | mov eax, vreg; // incarca registrul EAX cu continutul lui vreg 17 | }; 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/CarduriBancare.txt: -------------------------------------------------------------------------------- 1 | 6321987623459876 2 | Popescu Georgel 3 | 2028 8 4 | 176.98 5 | RON 6 | 6321987001659001 7 | Ionescu Marian 8 | 2027 12 9 | 1006.18 10 | RON 11 | 4720098769018080 12 | Georgescu Alexandru 13 | 2028 1 14 | 16.77 15 | USD 16 | 6321987623459878 17 | Ionescu Marian 18 | 2027 12 19 | 1006.18 20 | RON -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/CarduriBancare.txt: -------------------------------------------------------------------------------- 1 | Popescu Virgil Marius 2 | 6234999900001987 3 | 1298.04 4 | BCR 5 | 04/26 6 | Vasilescu George 7 | 6234990133441987 8 | 19.44 9 | BT 10 | 05/27 11 | Ionescu Alexandru 12 | 6235829929000001 13 | 888.55 14 | UniCredit 15 | 10/25 16 | Georgescu Marian 17 | 6235829929000201 18 | 128.14 19 | BCR 20 | 04/26 21 | -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/04_Preprocesare.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SUMA_GEN(NUME,TIP) TIP NUME(TIP vb1, TIP vb2) \ 4 | { return vb1 + vb2; } 5 | 6 | #define INTREG 1 7 | #define REAL 1 8 | 9 | #ifdef INTREG 10 | SUMA_GEN(sumai, int) 11 | #endif 12 | 13 | #ifdef REAL 14 | SUMA_GEN(sumaf, float) 15 | #endif 16 | 17 | int main() 18 | { 19 | #if defined(INTREG) && INTREG 20 | int x = 7, y = 9, z; 21 | z = sumai(x, y); 22 | #endif 23 | 24 | 25 | #if defined(REAL) && REAL 26 | float a = 7.8f, b = 9.5f, c; 27 | c = sumaf(a, b); 28 | #endif 29 | 30 | 31 | //#undef REAL 32 | // #define REAL 0 33 | #if defined(INTREG) && INTREG 34 | printf("\nz = %d", z); 35 | #endif 36 | #if defined(REAL) && REAL 37 | printf("\nc = %.2f", c); 38 | #endif 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/04_Preprocesare_1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SUMA_GEN(NUME,TIP) TIP NUME(TIP vb1, TIP vb2) \ 4 | { return vb1 + vb2; } 5 | 6 | //#define INTREG 1 7 | //#define REAL 2 8 | 9 | #ifdef INTREG 10 | SUMA_GEN(sumai, int) 11 | #endif 12 | 13 | #ifdef REAL 14 | SUMA_GEN(sumaf, float) 15 | #endif 16 | 17 | int main() 18 | { 19 | #if defined(INTREG) && INTREG 20 | int x = 7, y = 9, z; 21 | z = sumai(x, y); 22 | #endif 23 | 24 | 25 | #if defined(REAL) && REAL 26 | float a = 7.8f, b = 9.5f, c; 27 | c = sumaf(a, b); 28 | #endif 29 | 30 | 31 | // #undef REAL 32 | // #define REAL 0 33 | #if defined(INTREG) && INTREG 34 | printf("\nz = %d", z); 35 | #endif 36 | #if defined(REAL) && REAL 37 | printf("\nc = %.2f", c); 38 | #endif 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/03_Functii.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | double sumaValoare(float x, float y) { 4 | double s; 5 | s = x + y; 6 | return s; 7 | } 8 | 9 | void sumaAdresa(float x, float y, double* z) { 10 | *z = sumaValoare(x, y); 11 | } 12 | 13 | double sumaPointerFunctie(float x, float y, double (*pf)(float, float)) { 14 | x = x + 1; 15 | y = y + (float)2.2; 16 | 17 | double suma = pf(x, y); 18 | return suma; 19 | } 20 | 21 | 22 | int main() 23 | { 24 | float a = (float)1.2, b = 4.7f; 25 | double c; 26 | 27 | sumaAdresa(a, b, &c); 28 | printf("\nSuma apel functie parametri transfer prin valoare si adresa: %lf\n", c); 29 | 30 | // exemplu utilizare pointer la functie 31 | double (*pSumaVal)(float, float); 32 | pSumaVal = sumaValoare; 33 | c = sumaPointerFunctie(a, b, pSumaVal); 34 | printf("\nSuma apel functie cu parametru pointer la functie: %lf\n", c); 35 | 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/Grupa1055Proj.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | 23 | 24 | Resource Files 25 | 26 | 27 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/03_Pointeri.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | //// pointer constant la int 7 | //int i = 7, j = 9; 8 | //int* const pi = &i; 9 | //printf("\nAdresa(pi) = %p, Continut(pi) = %p\n", &pi, pi); 10 | ////pi = &j; // rescrierea zonei de memorie pi nu este posibila, fiind pointer constant 11 | 12 | int i = 7; 13 | //int const* pint; 14 | //pint = &i; 15 | //printf("\nAdresa(pint) = %p, Continut(pint) = %p\n", &pint, pint); 16 | ////*pint = i + 5; 17 | //i += 5; 18 | //printf("\nContinut(i) = %d\n", i); 19 | 20 | 21 | //const int* const pint2 = &i; 22 | //printf("\nAdresa(pint2) = %p, Continut(pint2) = %p\n", &pint2, pint2); 23 | //// *pint2 = i + 5; 24 | //printf("\nAdresa(pint2) = %p, Continut(pint2) = %p\n", &pint2, pint2); 25 | //i += 5; 26 | //printf("\nContinut(i) = %d\n", i); 27 | //printf("\nContinut(*pint2) = %d\n", *pint2); 28 | 29 | int* pint3 = NULL; 30 | 31 | // alocare memorie la runtime 32 | pint3 = (int*)malloc((unsigned int)i); // dimensiune zona de heap in nr de bytes 33 | 34 | pint3[0] = 1; // este ok! 35 | pint3[1] = 2; // NU este ok! 36 | 37 | // dezalocare memorie heap 38 | free(pint3); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/Grupa1059Proj.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Resource Files 20 | 21 | 22 | Resource Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /2024-2025/Grupa1075Sol/Grupa1075Proj/Grupa1075Proj.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Resource Files 20 | 21 | 22 | Resource Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/Grupa1058Proj.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | 23 | 24 | Resource Files 25 | 26 | 27 | Resource Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Proj/Grupa1062Proj.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | 23 | 24 | Resource Files 25 | 26 | 27 | Resource Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /2024-2025/Grupa1076Sol/Grupa1076Proj/Grupa1076Proj.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | 23 | 24 | Resource Files 25 | 26 | 27 | Resource Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/01_MemorieVariabile.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | 6 | int v[10][20]; // v este pointer la zona de memorie contingua alocata pt elementele matricei 7 | 8 | char* p = NULL; 9 | 10 | v[0][1] = 0; 11 | //v[-2][-3] = 0; 12 | //v[11][2] = 0; 13 | 14 | char i = 65; 15 | p = &i; 16 | 17 | //p[-2] = 0; 18 | 19 | //// pointer constant la char 20 | //int j = 9; 21 | //char* const pi = &i; 22 | //printf("\nAdresa(pi) = %p, Continut(pi) = %p\n", &pi, pi); 23 | ////pi = &j; 24 | 25 | //// pointer la char constant 26 | //char const* pint; 27 | //pint = &i; 28 | //printf("\nAdresa(pint) = %p, Continut(pint) = %p\n", &pint, pint); 29 | ////*pint = i + 5; 30 | //printf("\nContinut(i) = %d\n", i); 31 | 32 | // pointer constant la char constant 33 | const char* const pint2 = &i; 34 | printf("\nAdresa(pint2) = %p, Continut(pint2) = %p\n", &pint2, pint2); 35 | //*pint2 = i + 5; 36 | printf("\nAdresa(pint2) = %p, Continut(pint2) = %p\n", &pint2, pint2); 37 | 38 | 39 | return 0; 40 | } 41 | 42 | 43 | //int main() 44 | //{ 45 | // register int vreg; 46 | // int d; 47 | // 48 | // d = 8; 49 | // vreg = d; 50 | // 51 | // printf("vreg = %d\n", vreg); 52 | // 53 | // __asm 54 | // { 55 | // mov eax, vreg; // incarca registrul EAX cu continutul lui vreg 56 | // }; 57 | // 58 | //} 59 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/SeriaCProj.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Resource Files 20 | 21 | 22 | Resource Files 23 | 24 | 25 | Resource Files 26 | 27 | 28 | 29 | 30 | Source Files 31 | 32 | 33 | -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/SeriaDProj.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | 23 | 24 | Resource Files 25 | 26 | 27 | Resource Files 28 | 29 | 30 | Resource Files 31 | 32 | 33 | -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCSol.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.35325.158 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SeriaCProj", "SeriaCProj\SeriaCProj.vcxproj", "{0D70E070-2D87-4947-9D33-3C0559BE9A9D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0D70E070-2D87-4947-9D33-3C0559BE9A9D}.Debug|x64.ActiveCfg = Debug|x64 17 | {0D70E070-2D87-4947-9D33-3C0559BE9A9D}.Debug|x64.Build.0 = Debug|x64 18 | {0D70E070-2D87-4947-9D33-3C0559BE9A9D}.Debug|x86.ActiveCfg = Debug|Win32 19 | {0D70E070-2D87-4947-9D33-3C0559BE9A9D}.Debug|x86.Build.0 = Debug|Win32 20 | {0D70E070-2D87-4947-9D33-3C0559BE9A9D}.Release|x64.ActiveCfg = Release|x64 21 | {0D70E070-2D87-4947-9D33-3C0559BE9A9D}.Release|x64.Build.0 = Release|x64 22 | {0D70E070-2D87-4947-9D33-3C0559BE9A9D}.Release|x86.ActiveCfg = Release|Win32 23 | {0D70E070-2D87-4947-9D33-3C0559BE9A9D}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {ADFD92EA-BA47-4434-9DF0-FC1B0EED7E0E} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDSol.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.35325.158 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SeriaDProj", "SeriaDProj\SeriaDProj.vcxproj", "{9BB9F9AE-9DDD-4E78-BC81-459E1BFCD45C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9BB9F9AE-9DDD-4E78-BC81-459E1BFCD45C}.Debug|x64.ActiveCfg = Debug|x64 17 | {9BB9F9AE-9DDD-4E78-BC81-459E1BFCD45C}.Debug|x64.Build.0 = Debug|x64 18 | {9BB9F9AE-9DDD-4E78-BC81-459E1BFCD45C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {9BB9F9AE-9DDD-4E78-BC81-459E1BFCD45C}.Debug|x86.Build.0 = Debug|Win32 20 | {9BB9F9AE-9DDD-4E78-BC81-459E1BFCD45C}.Release|x64.ActiveCfg = Release|x64 21 | {9BB9F9AE-9DDD-4E78-BC81-459E1BFCD45C}.Release|x64.Build.0 = Release|x64 22 | {9BB9F9AE-9DDD-4E78-BC81-459E1BFCD45C}.Release|x86.ActiveCfg = Release|Win32 23 | {9BB9F9AE-9DDD-4E78-BC81-459E1BFCD45C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {43E4D19D-C6D1-487F-A6CB-9AD572B4543F} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Sol.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.35325.158 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Grupa1055Proj", "Grupa1055Proj\Grupa1055Proj.vcxproj", "{43C5BCEB-4B49-46C1-8906-5045ED9D25F6}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {43C5BCEB-4B49-46C1-8906-5045ED9D25F6}.Debug|x64.ActiveCfg = Debug|x64 17 | {43C5BCEB-4B49-46C1-8906-5045ED9D25F6}.Debug|x64.Build.0 = Debug|x64 18 | {43C5BCEB-4B49-46C1-8906-5045ED9D25F6}.Debug|x86.ActiveCfg = Debug|Win32 19 | {43C5BCEB-4B49-46C1-8906-5045ED9D25F6}.Debug|x86.Build.0 = Debug|Win32 20 | {43C5BCEB-4B49-46C1-8906-5045ED9D25F6}.Release|x64.ActiveCfg = Release|x64 21 | {43C5BCEB-4B49-46C1-8906-5045ED9D25F6}.Release|x64.Build.0 = Release|x64 22 | {43C5BCEB-4B49-46C1-8906-5045ED9D25F6}.Release|x86.ActiveCfg = Release|Win32 23 | {43C5BCEB-4B49-46C1-8906-5045ED9D25F6}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {DFD7E05B-1EE9-47EF-9F13-C38CA55685C0} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Sol.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.35325.158 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Grupa1058Proj", "Grupa1058Proj\Grupa1058Proj.vcxproj", "{377FB886-F3D3-4945-A726-2A52E14BA094}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {377FB886-F3D3-4945-A726-2A52E14BA094}.Debug|x64.ActiveCfg = Debug|x64 17 | {377FB886-F3D3-4945-A726-2A52E14BA094}.Debug|x64.Build.0 = Debug|x64 18 | {377FB886-F3D3-4945-A726-2A52E14BA094}.Debug|x86.ActiveCfg = Debug|Win32 19 | {377FB886-F3D3-4945-A726-2A52E14BA094}.Debug|x86.Build.0 = Debug|Win32 20 | {377FB886-F3D3-4945-A726-2A52E14BA094}.Release|x64.ActiveCfg = Release|x64 21 | {377FB886-F3D3-4945-A726-2A52E14BA094}.Release|x64.Build.0 = Release|x64 22 | {377FB886-F3D3-4945-A726-2A52E14BA094}.Release|x86.ActiveCfg = Release|Win32 23 | {377FB886-F3D3-4945-A726-2A52E14BA094}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {CE3C14AE-99C0-459F-A3D4-7CD27651B202} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Sol.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.35325.158 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Grupa1059Proj", "Grupa1059Proj\Grupa1059Proj.vcxproj", "{7BE42A0A-8BB5-4981-B5EB-806548ADB64C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {7BE42A0A-8BB5-4981-B5EB-806548ADB64C}.Debug|x64.ActiveCfg = Debug|x64 17 | {7BE42A0A-8BB5-4981-B5EB-806548ADB64C}.Debug|x64.Build.0 = Debug|x64 18 | {7BE42A0A-8BB5-4981-B5EB-806548ADB64C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {7BE42A0A-8BB5-4981-B5EB-806548ADB64C}.Debug|x86.Build.0 = Debug|Win32 20 | {7BE42A0A-8BB5-4981-B5EB-806548ADB64C}.Release|x64.ActiveCfg = Release|x64 21 | {7BE42A0A-8BB5-4981-B5EB-806548ADB64C}.Release|x64.Build.0 = Release|x64 22 | {7BE42A0A-8BB5-4981-B5EB-806548ADB64C}.Release|x86.ActiveCfg = Release|Win32 23 | {7BE42A0A-8BB5-4981-B5EB-806548ADB64C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {38BA69A8-2DC9-45A7-9F7B-A0EA0863F55D} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Sol.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.35325.158 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Grupa1062Proj", "Grupa1062Proj\Grupa1062Proj.vcxproj", "{633F595E-84E5-4E9C-A054-3B1EA23ADD49}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {633F595E-84E5-4E9C-A054-3B1EA23ADD49}.Debug|x64.ActiveCfg = Debug|x64 17 | {633F595E-84E5-4E9C-A054-3B1EA23ADD49}.Debug|x64.Build.0 = Debug|x64 18 | {633F595E-84E5-4E9C-A054-3B1EA23ADD49}.Debug|x86.ActiveCfg = Debug|Win32 19 | {633F595E-84E5-4E9C-A054-3B1EA23ADD49}.Debug|x86.Build.0 = Debug|Win32 20 | {633F595E-84E5-4E9C-A054-3B1EA23ADD49}.Release|x64.ActiveCfg = Release|x64 21 | {633F595E-84E5-4E9C-A054-3B1EA23ADD49}.Release|x64.Build.0 = Release|x64 22 | {633F595E-84E5-4E9C-A054-3B1EA23ADD49}.Release|x86.ActiveCfg = Release|Win32 23 | {633F595E-84E5-4E9C-A054-3B1EA23ADD49}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {083642A5-862A-46A9-B05B-8C05B41A248C} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /2024-2025/Grupa1075Sol/Grupa1075Sol.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.35325.158 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Grupa1075Proj", "Grupa1075Proj\Grupa1075Proj.vcxproj", "{E8AB4B7A-870A-474A-98AD-451B9E172D25}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {E8AB4B7A-870A-474A-98AD-451B9E172D25}.Debug|x64.ActiveCfg = Debug|x64 17 | {E8AB4B7A-870A-474A-98AD-451B9E172D25}.Debug|x64.Build.0 = Debug|x64 18 | {E8AB4B7A-870A-474A-98AD-451B9E172D25}.Debug|x86.ActiveCfg = Debug|Win32 19 | {E8AB4B7A-870A-474A-98AD-451B9E172D25}.Debug|x86.Build.0 = Debug|Win32 20 | {E8AB4B7A-870A-474A-98AD-451B9E172D25}.Release|x64.ActiveCfg = Release|x64 21 | {E8AB4B7A-870A-474A-98AD-451B9E172D25}.Release|x64.Build.0 = Release|x64 22 | {E8AB4B7A-870A-474A-98AD-451B9E172D25}.Release|x86.ActiveCfg = Release|Win32 23 | {E8AB4B7A-870A-474A-98AD-451B9E172D25}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {31C3DB2C-4C1A-45BE-87A2-0140DC3F9CFB} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /2024-2025/Grupa1076Sol/Grupa1076Sol.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.35325.158 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Grupa1076Proj", "Grupa1076Proj\Grupa1076Proj.vcxproj", "{6A3EBB2B-DC12-42E9-A696-2AC5A3AB9387}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {6A3EBB2B-DC12-42E9-A696-2AC5A3AB9387}.Debug|x64.ActiveCfg = Debug|x64 17 | {6A3EBB2B-DC12-42E9-A696-2AC5A3AB9387}.Debug|x64.Build.0 = Debug|x64 18 | {6A3EBB2B-DC12-42E9-A696-2AC5A3AB9387}.Debug|x86.ActiveCfg = Debug|Win32 19 | {6A3EBB2B-DC12-42E9-A696-2AC5A3AB9387}.Debug|x86.Build.0 = Debug|Win32 20 | {6A3EBB2B-DC12-42E9-A696-2AC5A3AB9387}.Release|x64.ActiveCfg = Release|x64 21 | {6A3EBB2B-DC12-42E9-A696-2AC5A3AB9387}.Release|x64.Build.0 = Release|x64 22 | {6A3EBB2B-DC12-42E9-A696-2AC5A3AB9387}.Release|x86.ActiveCfg = Release|Win32 23 | {6A3EBB2B-DC12-42E9-A696-2AC5A3AB9387}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {AE441013-FDA1-4C93-BAF6-93654456CE9D} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/01_TipuriDate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ARRAY_LENGTH 10 5 | 6 | int main() 7 | { 8 | char x = 'A'; 9 | char y = 1; 10 | char z = -1; 11 | float w = 65.64; 12 | 13 | char* pc = NULL; // pc = 0; 14 | 15 | printf("Adresa stack pc = %p\n", &pc); 16 | printf("pc = %p\n", pc); 17 | //printf("*pc = %d\n", *pc); // stop executie: eroare de runtime pentru pc == 0 18 | 19 | pc = &x; 20 | printf("Adresa stack pc = %p\n", &pc); 21 | printf("pc = %p\n", pc); // adresa de stack pt x 22 | printf("*pc = %d\n", *pc); // acces la locatia x 23 | 24 | pc = (char*)malloc(sizeof(char)); // alocare mem heap pe dimensiune de 1 byte 25 | printf("Adresa stack pc = %p\n", &pc); 26 | printf("pc = %p\n", pc); // adresa de heap alocata pe #22 27 | printf("*pc = %d\n", *pc); 28 | 29 | *pc = z; 30 | printf("Adresa stack pc = %p\n", &pc); 31 | printf("pc = %p\n", pc); // adresa de heap alocata pe linia #22 32 | printf("*pc = %d\n", *pc); 33 | 34 | free(pc); 35 | 36 | pc = (char*)malloc((ARRAY_LENGTH + 1) * sizeof(char)); // +1 deoarece am nevoie de byte terminator string 0x00 37 | 38 | for (unsigned char i = 0; i < ARRAY_LENGTH; i++) 39 | { 40 | pc[i] = x + i; 41 | } 42 | pc[ARRAY_LENGTH] = 0; 43 | for (unsigned char i = 0; i < ARRAY_LENGTH; i++) 44 | { 45 | printf("%c", pc[i]); // elemente vector accesate din mem heap prin pointer pc 46 | // afisate ca simboluri ASCII cu descriptor %c 47 | } 48 | 49 | printf("\n%s\n", pc); 50 | free(pc); 51 | 52 | char v[ARRAY_LENGTH + 1]; 53 | for (unsigned char i = 0; i < ARRAY_LENGTH; i++) 54 | { 55 | v[i] = x + i; 56 | } 57 | v[ARRAY_LENGTH] = 0; 58 | pc = v; 59 | printf("\nv = %s\n", pc); 60 | 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/03_Functii.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | double sumaValoare(float x, float y) { 5 | double s; 6 | s = x + y; 7 | return s; 8 | } 9 | 10 | void sumaAdresa(float x, float y, double* z) { 11 | *z = sumaValoare(x, y); 12 | } 13 | 14 | void sumaAdresaHeap(float x, float y, double* z) 15 | { 16 | z = (double*)malloc(sizeof(double)); 17 | *z = x + y; 18 | } 19 | 20 | void sumaAdresaHeap_v2(float x, float y, double* *z) 21 | { 22 | *z = (double*)malloc(sizeof(double)); 23 | **z = x + y; 24 | } 25 | 26 | 27 | double* sumaAdresaHeap_v3(float x, float y) 28 | { 29 | double* z = NULL; 30 | z = (double*)malloc(sizeof(double)); 31 | *z = x + y; 32 | 33 | return z; 34 | } 35 | 36 | int main() { 37 | float a = 1.2f, b = 4.7f; 38 | double c; 39 | 40 | sumaAdresa(a, b, &c); 41 | printf("\nSuma apel functie parametri transfer prin valoare si adresa: %lf = %f + %f\n", c, a, b); 42 | 43 | double* p_suma = NULL; 44 | //sumaAdresaHeap(a, b, p_suma); 45 | sumaAdresaHeap_v2(a, b, &p_suma); 46 | printf("\nSuma apel functie parametri transfer prin valoare si POINTER prin adresa: %lf = %f + %f\n", *p_suma, a, b); 47 | 48 | p_suma = sumaAdresaHeap_v3(a, b); 49 | printf("\nSuma apel functie parametri transfer prin valoare si POINTER obtinut prin return din functie: %lf = %f + %f\n", *p_suma, a, b); 50 | 51 | free(p_suma); 52 | 53 | 54 | // definire si utilizare pointer la functie 55 | double (*pSumaVal)(float, float); 56 | pSumaVal = sumaValoare; // scriere adresa functie (din seg de cod) in pSumaVal 57 | c = pSumaVal((float)(a + 1), (float)(b + 2.2)); // apel functie sumaValoare prin pointer pSumaVal 58 | printf("\nSuma apel functie prin pointer la functie: %lf\n", c); 59 | 60 | pSumaVal = &sumaValoare; 61 | c = pSumaVal(a + 1, b + 2.2); 62 | printf("\nSuma apel functie prin pointer la functie: %lf\n", c); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/01_TipuriDate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define NR_ELEMENTE 1 5 | #define NR_ELEMENTE_VECTOR 10 6 | 7 | int main() 8 | { 9 | char x = 65; 10 | char y = -2; 11 | float z = (float)65.64; 12 | 13 | printf("x = %d, y = %d, z = %f\n", x, y, z); 14 | printf("x = %c, y = %d, z = %f\n", x, y, z); 15 | 16 | char* pc = NULL; // pc = 0; 17 | printf("Adresa stack pc = %p\n", &pc); 18 | printf("Continut pc = %p\n", pc); 19 | //printf("Valoare la destinatie *pc = %d\n", *pc); // nu se acceseaza continut de la adresa nula 20 | 21 | pc = &x; 22 | printf("Adresa stack pc = %p\n", &pc); 23 | printf("Continut pc = %p\n", pc); 24 | printf("Valoare la destinatie *pc = %d\n", *pc); 25 | printf("Valoare la destinatie *pc = %d\n", pc[0]); 26 | 27 | pc = (char*) malloc(NR_ELEMENTE * sizeof(char)); 28 | *pc = y; // pc[0] = y; *(pc + 0) = y 29 | printf("Adresa stack pc = %p\n", &pc); 30 | printf("Continut pc = %p\n", pc); 31 | printf("Valoare la destinatie *pc = %d\n", *pc); 32 | 33 | free(pc); 34 | pc = (char*)malloc((NR_ELEMENTE_VECTOR + 1) * sizeof(char)); 35 | for (unsigned char i = 0; i < NR_ELEMENTE_VECTOR; i++) 36 | { 37 | pc[i] = (char)(x + i); 38 | } 39 | pc[NR_ELEMENTE_VECTOR] = 0; // scrierea terminatorului de string pe ultimul byte din vector = 0x00 40 | 41 | printf("Adresa stack pc = %p\n", &pc); 42 | printf("Continut pc = %p\n", pc); 43 | for (unsigned int i = 0; i < NR_ELEMENTE_VECTOR; i++) 44 | { 45 | printf("%c --> %d\n", pc[i], pc[i]); // asociere simbol ASCII --> cod ASCII 46 | } 47 | printf("\n"); 48 | 49 | printf("%s in memorie heap\n", pc); 50 | 51 | free(pc); 52 | 53 | char v[NR_ELEMENTE_VECTOR + 1]; 54 | pc = v; 55 | for (unsigned char i = 0; i < NR_ELEMENTE_VECTOR; i++) 56 | { 57 | v[i] = (char)(x + i); 58 | } 59 | v[NR_ELEMENTE_VECTOR] = 0; 60 | printf("v = %s in memorie stack\n", pc); 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1076Sol/Grupa1076Proj/01_DataTypes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define BYTEARRAY_SIZE 10 5 | #define LINE_SIZE 8 6 | #define COLUMN_SIZE 10 7 | 8 | int main() 9 | { 10 | char x = 65; 11 | char y = -2; 12 | 13 | float z = 65.64; 14 | 15 | char* p = NULL; 16 | printf("Stack memory address where p is allocated = %p\n", &p); 17 | printf("Content of p = %p\n", p); 18 | //printf("Content pointed by p = %d\n", *p); 19 | 20 | p = &x; // write stack seg address over variable p 21 | printf("Stack memory address where p is allocated = %p\n", &p); 22 | printf("Content of p = %p\n", p); 23 | printf("Content pointed by p = %d\n", *p); 24 | 25 | p = (char*)malloc(1 * sizeof(char)); // get heap seg address to store it over variable p 26 | printf("Stack memory address where p is allocated = %p\n", &p); 27 | printf("Content of p = %p\n", p); 28 | printf("Content pointed by p = %d\n", *p); 29 | 30 | *p = x; // write actual content of x to memory location pointed by p 31 | printf("Stack memory address where p is allocated = %p\n", &p); 32 | printf("Content of p = %p\n", p); 33 | printf("Content pointed by p = %d\n", *p); 34 | 35 | free(p); // deallocate heap memory 36 | 37 | p = (char*)malloc((BYTEARRAY_SIZE + 1) * sizeof(char)); 38 | 39 | for (unsigned char i = 0; i < BYTEARRAY_SIZE; i++) 40 | { 41 | p[i] = x + i; 42 | } 43 | p[BYTEARRAY_SIZE] = 0; // store the null terminator byte at the last allocated byte in the bytearray 44 | for (unsigned char i = 0; i < BYTEARRAY_SIZE; i++) 45 | { 46 | printf("%d --> %c\n", p[i], p[i]); 47 | } 48 | 49 | printf("%s\n", p); 50 | 51 | free(p); 52 | 53 | char v[BYTEARRAY_SIZE + 1]; 54 | for (unsigned char i = 0; i < BYTEARRAY_SIZE; i++) 55 | { 56 | v[i] = x + i; 57 | } 58 | v[BYTEARRAY_SIZE] = 0; 59 | 60 | p = v; 61 | printf("%s\n", p); 62 | 63 | char M[10][9]; 64 | char** pM = NULL; 65 | 66 | // step1: allocate the intermediary array of heap addresses of the lines 67 | pM = (char**)malloc(LINE_SIZE * sizeof(char*)); 68 | // step2: allocate heap memory for the lines 69 | for (unsigned char i = 0; i < LINE_SIZE; i++) 70 | { 71 | pM[i] = (char*)malloc(COLUMN_SIZE * sizeof(char)); // starting heap address of line #i 72 | } 73 | 74 | // store actual values over the items pM[i][j] 75 | 76 | 77 | // deallocate the matrix in heap memory 78 | // step1: deallocate the farest heap locations (the lines with actual values) 79 | for (unsigned char i = 0; i < LINE_SIZE; i++) 80 | { 81 | free(pM[i]); // deallocate the line #i 82 | } 83 | // step2: deallocate the nearest location 84 | free(pM); // intermediary arrays of pointers to lines is deallocated 85 | 86 | return 0; 87 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Proj/01_TipuriDate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define NR_ELEMENTE 10 5 | #define NR_LINII 10 6 | #define NR_COLOANE 10 7 | 8 | int main() 9 | { 10 | char x = 65; 11 | char y = -2; 12 | 13 | float z = (float)65.64; 14 | 15 | char* p_char = NULL; 16 | printf("Adresa stack seg pentru p_char = %p\n", &p_char); 17 | printf("Continut pentru p_char = %p\n", p_char); 18 | //printf("Valoare accesata prin pointer p_char = %d\n", *p_char); 19 | 20 | p_char = &x; 21 | printf("Adresa stack seg pentru p_char = %p\n", &p_char); 22 | printf("Continut pentru p_char = %p\n", p_char); 23 | printf("Valoare accesata prin pointer p_char = %d\n", *p_char); 24 | 25 | p_char = (char*)malloc(sizeof(char)); 26 | printf("Adresa stack seg pentru p_char = %p\n", &p_char); 27 | printf("Continut pentru p_char = %p\n", p_char); 28 | printf("Valoare accesata prin pointer p_char = %d\n", *p_char); 29 | 30 | p_char[0] = x; 31 | printf("Adresa stack seg pentru p_char = %p\n", &p_char); 32 | printf("Continut pentru p_char = %p\n", p_char); 33 | printf("Valoare accesata prin pointer p_char = %d\n", *p_char); 34 | 35 | free(p_char); 36 | printf("Adresa stack seg pentru p_char = %p\n", &p_char); 37 | printf("Continut pentru p_char = %p\n", p_char); 38 | printf("Valoare accesata prin pointer p_char = %d\n", *p_char); 39 | 40 | p_char = malloc((NR_ELEMENTE + 1) * sizeof(char)); 41 | 42 | for (unsigned char i = 0; i < NR_ELEMENTE; i++) 43 | { 44 | p_char[i] = x + i; 45 | } 46 | p_char[NR_ELEMENTE] = 0; // terminatorul de string in C 47 | 48 | for (unsigned char i = 0; i < NR_ELEMENTE; i++) 49 | { 50 | printf("%d --> %c\n", p_char[i], p_char[i]); 51 | } 52 | 53 | printf("%s in memorie heap\n", p_char); 54 | 55 | free(p_char); 56 | 57 | char v[NR_ELEMENTE + 1]; // masiv uni0-dimensional alocat in stack seg 58 | p_char = v; 59 | 60 | for (unsigned char i = 0; i < NR_ELEMENTE; i++) 61 | { 62 | v[i] = x + i; 63 | } 64 | v[NR_ELEMENTE] = 0; 65 | printf("%s in memorie stack\n", p_char); 66 | 67 | char** p_Mat = NULL; 68 | // alocare vector de adrese de linii nivel 1 de indirectare 69 | p_Mat = (char**)malloc(NR_LINII * sizeof(char*)); 70 | for (unsigned char i = 0; i < NR_LINII; i++) 71 | p_Mat[i] = (char*)malloc(NR_COLOANE * sizeof(char)); // alocare vector de elemnte per linian i (nivel 2 matrice) 72 | 73 | // utilizare matrice p_Mat[i][j] --> acces la element linia i si coloana j 74 | 75 | // dezalocare matrice 76 | for (unsigned char i = 0; i < NR_LINII; i++) 77 | free(p_Mat[i]); // dezalocare elemente (vector nivel 2) linia i din matrice 78 | free(p_Mat); // dezalocare vector de adrese de linii de pe nivelul 1 79 | 80 | return 0; 81 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1075Sol/Grupa1075Proj/01_DataTypes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define BYTEARRAY_SIZE 10 5 | #define LINE_SIZE 6 6 | #define COLUMN_SIZE 9 7 | 8 | int main() 9 | { 10 | char x = 65; // char x = 0x41; OR char x = 'A'; 11 | unsigned char y = -2; 12 | 13 | float z = (float)65.64; 14 | 15 | char* p = NULL; 16 | printf("Memory Address of location p = %p \n", &p); 17 | printf("Content of location p = %p \n", p); 18 | //printf("Content of pointed location p = %d \n", *p); 19 | 20 | p = &x; // write p with the stack memory address of x 21 | printf("Memory Address of location p = %p \n", &p); 22 | printf("Content of location p = %p \n", p); 23 | printf("Content of pointed location p = %d \n", *p); 24 | 25 | p = (char*)malloc(1 * sizeof(char)); // heap memory allocation for one single char location 26 | printf("Memory Address of location p = %p \n", &p); 27 | printf("Content of location p = %p \n", p); 28 | printf("Content of pointed location p = %d \n", *p); 29 | 30 | *p = x; // write content of x (65) over the memory pointed by p 31 | printf("Memory Address of location p = %p \n", &p); 32 | printf("Content of location p = %p \n", p); 33 | printf("Content of pointed location p = %d \n", *p); 34 | 35 | free(p); // deallocation of heap memory pointer by p 36 | 37 | p = (char*)malloc((BYTEARRAY_SIZE + 1)* sizeof(char)); // allocate a byte array 38 | for (unsigned char i = 0; i < BYTEARRAY_SIZE; i++) 39 | { 40 | p[i] = x + i; // p[i] points to heap mem for the item having the offset i(same like compile-time allocated array) 41 | } 42 | p[BYTEARRAY_SIZE] = 0; // save the null byte right after the last item in the bytearray 43 | for (unsigned char i = 0; i < BYTEARRAY_SIZE; i++) 44 | { 45 | printf("%d --> %c\n", p[i], p[i]); 46 | } 47 | 48 | printf("%s\n", p); 49 | free(p); 50 | 51 | char v[BYTEARRAY_SIZE + 1]; 52 | p = v; // p contains the starting point (mem address) of the array v 53 | for (unsigned char i = 0; i < BYTEARRAY_SIZE; i++) 54 | { 55 | v[i] = x + i; 56 | } 57 | v[BYTEARRAY_SIZE] = 0; // null byte terminator is put on the last item in array v 58 | printf("%s\n", p); // array y is printed out by using the pointer p 59 | 60 | char** pM = NULL; 61 | // matrix allocation 62 | pM = (char**)malloc(LINE_SIZE * sizeof(char*)); // allocation of the 1st level of the matrix in heap 63 | for (unsigned char i = 0; i < LINE_SIZE; i++) 64 | { 65 | pM[i] = (char*)malloc(COLUMN_SIZE * sizeof(char)); // allocation of line #i; hep memory address stored on intermediary level (pM[i]) 66 | } 67 | 68 | // store relevant content over each matrix item accessed by pM[i][j] 69 | 70 | 71 | // matrix deallocation 72 | // deallocate the farest heap locations (the lines with the actual values) 73 | for (unsigned char i = 0; i < LINE_SIZE; i++) 74 | { 75 | free(pM[i]); // deallocate line #i 76 | } 77 | // deallocate the nearest heap location 78 | free(pM); // deallocate the intermediary array of addresses to the lines 79 | 80 | return 0; 81 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/01_TipuriDate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define NR_ELEMENTE 10 5 | #define NR_LINII 10 6 | #define NR_COLOANE 9 7 | 8 | int main() 9 | { 10 | char x = 65; 11 | char y = -2; 12 | 13 | float z = 65.64f; 14 | 15 | char* p_char = NULL; 16 | printf("Adresa stack pointer p_char = %p\n", &p_char); 17 | printf("Continut pointer p_char = %p\n", p_char); 18 | //printf("Continut zona pointata de p_char = %d\n", *p_char); // eroare la run-time; adresa nu exista/incorecta 19 | 20 | p_char = &x; 21 | printf("Adresa stack pointer p_char = %p\n", &p_char); 22 | printf("Continut pointer p_char = %p\n", p_char); 23 | printf("Continut zona pointata de p_char = %d\n", *p_char); // p_char[0] in loc de *p_char 24 | 25 | p_char = (char*)malloc(sizeof(char)); // alocare mem heap 26 | printf("Adresa stack pointer p_char = %p\n", &p_char); 27 | printf("Continut pointer p_char = %p\n", p_char); 28 | printf("Continut zona pointata de p_char = %d\n", *p_char); 29 | 30 | p_char[0] = x; // *p_char = x; 31 | printf("Adresa stack pointer p_char = %p\n", &p_char); 32 | printf("Continut pointer p_char = %p\n", p_char); 33 | printf("Continut zona pointata de p_char = %d\n", *p_char); 34 | 35 | free(p_char); // dezalocare memorie heap 36 | 37 | printf("Adresa stack pointer p_char = %p\n", &p_char); 38 | printf("Continut pointer p_char = %p\n", p_char); 39 | printf("Continut zona pointata de p_char = %d\n", *p_char); 40 | 41 | p_char = (char*)malloc((NR_ELEMENTE + 1) * sizeof(char)); 42 | for (unsigned char i = 0; i < NR_ELEMENTE; i++) 43 | { 44 | p_char[i] = x + i; 45 | } 46 | p_char[NR_ELEMENTE] = 0; // scriere terminator string pe ultimul byte alocat 47 | 48 | for (unsigned char i = 0; i < NR_ELEMENTE; i++) 49 | { 50 | printf("%c --> %d\n", p_char[i], p_char[i]); 51 | } 52 | printf("\n"); 53 | 54 | printf("%s in memorie heap\n", p_char); 55 | 56 | free(p_char); 57 | 58 | char v[NR_ELEMENTE + 1]; 59 | p_char = v; 60 | 61 | for (unsigned char i = 0; i < NR_ELEMENTE; i++) 62 | { 63 | v[i] = x + i; 64 | } 65 | v[NR_ELEMENTE] = 0; // scriere terminator string pe ultimul byte din vector 66 | printf("%s in memorie stack\n", p_char); // afisare string din zona de mem stack alocata lui v 67 | 68 | char** M = NULL; 69 | // alocare nivel 1 al matricei (nr de linii) 70 | M = (char**)malloc(NR_LINII * sizeof(char*)); // alocare vector de pointeri la linii 71 | for (unsigned char i = 0; i < NR_LINII; i++) 72 | // alocare nivel 2 al matricei 73 | M[i] = (char*)malloc(NR_COLOANE * sizeof(char)); // alocare mem heap pentru linia i; 74 | // adresa de inceput a liniei i este stocata in M[i] 75 | 76 | // initializare & utilizare elemente matrice 77 | 78 | // dezalocare matrice 79 | for (unsigned char i = 0; i < NR_LINII; i++) 80 | free(M[i]); // dezalocare vector de elemente char aferent liniei i (nivel 2 al matricei) 81 | free(M); // dezalocare vector de adrese de inceput de linii (nivel 1 al matricei) 82 | 83 | return 0; 84 | } -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/05_ListeDuble.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define LINESIZE 128 7 | 8 | struct Student { 9 | int id; 10 | char* nume; 11 | float medie; // data derivata 12 | }; 13 | 14 | struct NodD { 15 | struct Student* st; 16 | struct NodD* next, * prev; 17 | }; 18 | 19 | struct ListaDbl { 20 | struct NodD* p, * u; 21 | }; 22 | 23 | struct ListaDbl inserareListaDubla(struct ListaDbl lstD, struct Student* pStd) { 24 | struct NodD* nou; 25 | nou = (struct NodD*)malloc(sizeof(struct NodD)); 26 | nou->st = pStd; 27 | nou->next = 0; 28 | nou->prev = lstD.u; 29 | 30 | if (!lstD.p) 31 | { 32 | // lista este empty pt c nu adresa primului nod este nula 33 | lstD.p = lstD.u = nou; 34 | } 35 | else { 36 | // lista dubla are cel putin 1 nod 37 | lstD.u->next = nou; 38 | lstD.u = nou; 39 | } 40 | 41 | return lstD; 42 | 43 | } 44 | 45 | void parseListDblInvers(struct ListaDbl lstD) { 46 | struct NodD* tmp = lstD.u; 47 | while (tmp) { 48 | printf("%d %s %5.2f\n", tmp->st->id, tmp->st->nume, tmp->st->medie); 49 | 50 | tmp = tmp->prev; 51 | } 52 | } 53 | 54 | struct ListaDbl stergereStudentDbl(struct ListaDbl lstD) { 55 | struct NodD* tmp = lstD.p; 56 | 57 | if (tmp) { // exista cel putin un nod in lista dubla 58 | lstD.p = lstD.p->next; 59 | if (lstD.p) 60 | lstD.p->prev = 0; 61 | else { 62 | // exista un singur nod in lista 63 | lstD.u = 0; 64 | } 65 | 66 | free(tmp->st->nume); 67 | free(tmp->st); 68 | free(tmp); 69 | } 70 | 71 | return lstD; 72 | } 73 | 74 | int main() 75 | { 76 | struct ListaDbl lstStuds; 77 | lstStuds.p = lstStuds.u = 0; 78 | 79 | struct Student* pStud; 80 | 81 | FILE* f; 82 | f = fopen("Studenti.txt", "r"); 83 | 84 | char* token, file_buf[LINESIZE], sep_list[] = ",\n"; 85 | 86 | while (fgets(file_buf, sizeof(file_buf), f)) { 87 | token = strtok(file_buf, sep_list); 88 | pStud = (struct Student*)malloc(sizeof(struct Student)); 89 | pStud->id = atoi(token); 90 | 91 | token = strtok(NULL, sep_list); 92 | pStud->nume = (char*)malloc((strlen(token) + 1) * sizeof(char)); 93 | strcpy(pStud->nume, token); 94 | 95 | token = strtok(NULL, sep_list); 96 | pStud->medie = (float)atof(token); 97 | 98 | token = strtok(NULL, sep_list); 99 | if (token) 100 | printf("\nEroare preluare token!"); 101 | 102 | // inserare nod la inceputul listei 103 | lstStuds = inserareListaDubla(lstStuds, pStud); 104 | } 105 | 106 | printf("\nLista dubla dupa creare:\n"); 107 | parseListDblInvers(lstStuds); 108 | 109 | lstStuds = stergereStudentDbl(lstStuds); 110 | 111 | printf("\nLista dubla dupa stergere student:\n"); 112 | parseListDblInvers(lstStuds); 113 | 114 | while (lstStuds.p) 115 | lstStuds = stergereStudentDbl(lstStuds); 116 | 117 | printf("\nLista dubla dupa dezalocare:\n"); 118 | parseListDblInvers(lstStuds); 119 | 120 | fclose(f); 121 | 122 | return 0; 123 | } -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/05_ListeDuble.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define LINESIZE 128 7 | 8 | struct Student { 9 | int id; 10 | char* nume; 11 | float medie; // data derivata 12 | }; 13 | 14 | struct NodD { 15 | struct Student* st; 16 | struct NodD* next, * prev; 17 | }; 18 | 19 | struct ListaDbl { 20 | struct NodD* p, * u; 21 | }; 22 | 23 | struct ListaDbl inserareListaDubla(struct ListaDbl lstD, struct Student* pStd) { 24 | struct NodD* nou; 25 | nou = (struct NodD*)malloc(sizeof(struct NodD)); 26 | nou->st = pStd; 27 | nou->next = 0; 28 | nou->prev = lstD.u; 29 | 30 | if (!lstD.p) 31 | lstD.p = lstD.u = nou; 32 | else { 33 | lstD.u->next = nou; 34 | lstD.u = nou; 35 | } 36 | 37 | return lstD; 38 | 39 | } 40 | 41 | void parseListDblInvers(struct ListaDbl lstD) { 42 | struct NodD* tmp = lstD.u; 43 | while (tmp) { 44 | printf("%d %s %5.2f\n", tmp->st->id, tmp->st->nume, tmp->st->medie); 45 | 46 | tmp = tmp->prev; 47 | } 48 | } 49 | 50 | struct ListaDbl stergereStudentDbl(struct ListaDbl lstD) { 51 | struct NodD* tmp = lstD.p; 52 | 53 | if (tmp) { // exista cel putin un nod in lista dubla 54 | lstD.p = lstD.p->next; 55 | if (lstD.p) 56 | lstD.p->prev = 0; 57 | else { 58 | // exista un singur nod in lista 59 | lstD.u = 0; // lstD.u = NULL; 60 | } 61 | 62 | free(tmp->st->nume); // dezalocare nume student 63 | free(tmp->st); // dealocare structura Student 64 | free(tmp); // dezalocare nod lista dubla 65 | } 66 | 67 | return lstD; 68 | } 69 | 70 | int main() 71 | { 72 | struct ListaDbl lstStuds; 73 | lstStuds.p = lstStuds.u = 0; 74 | 75 | struct Student* pStud; 76 | 77 | FILE* f; 78 | f = fopen("Studenti.txt", "r"); 79 | 80 | char* token, file_buf[LINESIZE], sep_list[] = ",\n"; 81 | 82 | while (fgets(file_buf, sizeof(file_buf), f)) { 83 | token = strtok(file_buf, sep_list); 84 | pStud = (struct Student*)malloc(sizeof(struct Student)); 85 | pStud->id = atoi(token); 86 | 87 | token = strtok(NULL, sep_list); 88 | pStud->nume = (char*)malloc((strlen(token) + 1) * sizeof(char)); 89 | strcpy(pStud->nume, token); 90 | 91 | token = strtok(NULL, sep_list); 92 | pStud->medie = (float)atof(token); 93 | 94 | token = strtok(NULL, sep_list); 95 | if (token) 96 | printf("\nEroare preluare token!"); 97 | 98 | // inserare nod la inceputul listei 99 | lstStuds = inserareListaDubla(lstStuds, pStud); 100 | } 101 | 102 | printf("\nLista dubla dupa creare:\n"); 103 | parseListDblInvers(lstStuds); 104 | 105 | lstStuds = stergereStudentDbl(lstStuds); 106 | 107 | printf("\nLista dubla dupa stergere student:\n"); 108 | parseListDblInvers(lstStuds); 109 | 110 | // dezalocare structura lista dubla 111 | while (lstStuds.p) 112 | lstStuds = stergereStudentDbl(lstStuds); 113 | 114 | printf("\nLista dubla dupa dezalocare:\n"); 115 | parseListDblInvers(lstStuds); 116 | 117 | fclose(f); 118 | 119 | return 0; 120 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/02_Masive.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define CARD_NO_LENGTH 16 6 | #define MONEDA_COD_LENGTH 3 7 | #define VECTOR_LENGTH 20 8 | 9 | struct CardBancar 10 | { 11 | char nr_card[CARD_NO_LENGTH + 1]; // +1 pt terminator de string (char[]) 12 | char* detinator; 13 | char expira_la[6]; 14 | float sold; 15 | char moneda[MONEDA_COD_LENGTH + 1]; 16 | }; 17 | 18 | typedef struct CardBancar CardBancar; 19 | 20 | int main() 21 | { 22 | CardBancar v_cards[VECTOR_LENGTH]; 23 | CardBancar* pv_cards = NULL; 24 | 25 | printf("Dimensiune CardBancar = %d\n", sizeof(CardBancar)); 26 | printf("Dimensiune vector v_cards = %d\n", sizeof(v_cards)); 27 | printf("Dimensiune pointer pv_cards = %d\n", sizeof(pv_cards)); 28 | 29 | // preluarea datelor din fisierul CarduriBancare.txt si incarcarea acestora in vectorul v_cards 30 | 31 | FILE* f; // pointer la structura FILE (handler de fisier) 32 | 33 | f = fopen("CarduriBancare.txt", "r"); 34 | 35 | unsigned char i = 0; 36 | char titular[150]; 37 | fscanf(f, "%[^,],%[^,],%[^,],%f,%[^\n]", v_cards[i].nr_card, titular, 38 | v_cards[i].expira_la, &(v_cards[i].sold), v_cards[i].moneda); 39 | while (!feof(f) && i < VECTOR_LENGTH) // 1. conditie aplicata dupa o incercare de a citi nr card bancar 40 | // 2. i nu poate depasi numarul maxim de elemente definit pt v_cards 41 | { 42 | v_cards[i].detinator = malloc(strlen(titular) + 1); // +1 pt terminatorul de string (byte 0x00) 43 | strcpy(v_cards[i].detinator, titular); // copiere string nume detinator in vector, offset i, campul detinator 44 | 45 | i += 1; // acces la urmatorul card bancar 46 | fscanf(f, "\n"); 47 | fscanf(f, "%[^,],%[^,],%[^,],%f,%[^\n]", v_cards[i].nr_card, titular, 48 | v_cards[i].expira_la, &(v_cards[i].sold), v_cards[i].moneda); // citire nr card de pe linia urmatoare 49 | } 50 | 51 | unsigned char vector_size = i; 52 | for (i = 0; i < vector_size; i++) 53 | { 54 | printf("%s %s\n", v_cards[i].nr_card, v_cards[i].detinator); 55 | } 56 | 57 | 58 | // pointer pv_cards la vectorul de carduri v_cards 59 | pv_cards = v_cards; 60 | for (i = 0; i < vector_size; i++) 61 | { 62 | printf("%s %s\n", pv_cards[i].nr_card, pv_cards[i].detinator); 63 | } 64 | 65 | pv_cards = malloc(vector_size * sizeof(CardBancar)); 66 | 67 | for (i = 0; i < vector_size; i++) 68 | { 69 | pv_cards[i] = v_cards[i]; // temporar avem partajare de memorie heap pt detinator 70 | // eliminare partajare de mem heap intre doi vectori v_cards si pv_cards 71 | pv_cards[i].detinator = malloc(strlen(v_cards[i].detinator) + 1); 72 | strcpy(pv_cards[i].detinator, v_cards[i].detinator); 73 | } 74 | 75 | 76 | // prelucrare date de tip CardBancar 77 | 78 | // dezalocare vector din heap 79 | for (i = 0; i < vector_size; i++) 80 | { 81 | free(pv_cards[i].detinator); 82 | } 83 | free(pv_cards); 84 | // dezalocare stringuri detinator pentru elementele din v_cards 85 | for (i = 0; i < vector_size; i++) 86 | { 87 | free(v_cards[i].detinator); 88 | } 89 | fclose(f); 90 | return 0; 91 | } -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/04_ListeSimple.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define LINESIZE 128 9 | 10 | struct Student { 11 | int id; 12 | char* nume; 13 | float medie; // data derivata 14 | }; 15 | 16 | struct Nod { 17 | struct Student st; // Student *st; 18 | struct Nod* next; 19 | }; 20 | 21 | struct Nod* inserareLista(struct Nod* p, struct Student s) { 22 | struct Nod* nou; 23 | nou = (struct Nod*)malloc(1 * sizeof(struct Nod)); 24 | 25 | nou->st = s; 26 | nou->next = p; 27 | 28 | return nou; 29 | } 30 | 31 | void parseList(struct Nod* p) { 32 | while (p) { 33 | printf("%d %s %5.2f\n", p->st.id, p->st.nume, p->st.medie); 34 | 35 | p = p->next; 36 | } 37 | } 38 | 39 | struct Student stergereStudent(struct Nod** p) { 40 | struct Nod* tmp = *p; 41 | struct Student s; 42 | if (tmp) { 43 | if (tmp->next) { // cel putin doua noduri in lista 44 | while (tmp->next->next) 45 | tmp = tmp->next; 46 | s = tmp->next->st; // salvare student in var locala s 47 | 48 | free(tmp->next); // dezalocare nod lista simpla 49 | tmp->next = 0; // actualizare adresa legatura 50 | } 51 | else { // caz particular; un singur nod in lista 52 | s = tmp->st; // salvare student din cap lista 53 | 54 | free(tmp); // dezalocare cap de lista 55 | *p = 0; 56 | } 57 | } 58 | 59 | return s; 60 | } 61 | 62 | int main() { 63 | 64 | struct Nod* prim = NULL; // pointer adresa nod inceput lista -> gestionare 65 | // structura de date lista simpla 66 | 67 | struct Student stud; // buffer incarcare date din fisier 68 | // suprascris pentru fiecare student preluat din fisier 69 | 70 | FILE* f; 71 | f = fopen("Studenti.txt", "r"); 72 | 73 | char* token, file_buf[LINESIZE], sep_list[] = ",\n"; 74 | while (fgets(file_buf, sizeof(file_buf), f)) { 75 | token = strtok(file_buf, sep_list); 76 | stud.id = atoi(token); 77 | 78 | token = strtok(NULL, sep_list); 79 | stud.nume = (char*)malloc((strlen(token) + 1) * sizeof(char)); 80 | strcpy(stud.nume, token); 81 | 82 | token = strtok(NULL, sep_list); 83 | stud.medie = (float)atof(token); 84 | 85 | token = strtok(NULL, sep_list); 86 | if (token) 87 | printf("\nEroare preluare token!"); 88 | 89 | // inserare nod la inceputul listei 90 | prim = inserareLista(prim, stud); 91 | } 92 | 93 | printf("\nLista dupa creare:\n"); 94 | parseList(prim); 95 | 96 | 97 | if (prim) // stergere student (dezalocare ultim nod) 98 | stud = stergereStudent(&prim); 99 | 100 | printf("\nLista dupa stergere student:\n"); 101 | parseList(prim); 102 | printf("Student extras: %d %s\n", stud.id, stud.nume); 103 | 104 | // dezalocare structura lista simpla 105 | free(stud.nume); 106 | while (prim) 107 | { 108 | stud = stergereStudent(&prim); 109 | free(stud.nume); 110 | } 111 | 112 | printf("Lista dupa dezalocare:\n"); 113 | parseList(prim); 114 | 115 | fclose(f); 116 | 117 | return 0; 118 | } -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/05_ListeSimple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define LINESIZE 128 7 | 8 | struct Student { 9 | int id; 10 | char* nume; 11 | float medie; // data derivata 12 | }; 13 | 14 | struct Nod { 15 | struct Student st; // Student *st; 16 | struct Nod* next; 17 | }; 18 | 19 | struct Nod* inserareLista(struct Nod* p, struct Student s) { 20 | struct Nod* nou; 21 | nou = (struct Nod*)malloc(1 * sizeof(struct Nod)); 22 | 23 | nou->st = s; 24 | nou->next = p; 25 | 26 | return nou; 27 | } 28 | 29 | void parseList(struct Nod* p) { 30 | while (p) { 31 | printf("%d %s %5.2f\n", p->st.id, p->st.nume, p->st.medie); 32 | 33 | p = p->next; 34 | } 35 | } 36 | 37 | struct Student stergereStudent(struct Nod** p) { 38 | struct Nod* tmp = *p; // *p este continut de la adresa stocata in parametrul p 39 | struct Student s; 40 | if (tmp) { 41 | if (tmp->next) { // cel putin doua noduri in lista 42 | while (tmp->next->next) 43 | tmp = tmp->next; 44 | s = tmp->next->st; // salvare student in var locala s 45 | 46 | free(tmp->next); // dezalocare nod lista simpla 47 | tmp->next = 0; // actualizare adresa legatura 48 | } 49 | else { // caz particular; un singur nod in lista 50 | s = tmp->st; // salvare student din cap lista 51 | 52 | free(tmp); // dezalocare cap de lista 53 | *p = 0; // *p = NULL; 54 | } 55 | } 56 | 57 | return s; 58 | } 59 | 60 | int main() { 61 | 62 | struct Nod* prim = 0; // pointer adresa nod inceput lista -> gestionare 63 | // structura de date lista simpla 64 | 65 | struct Student stud; // buffer incarcare date din fisier 66 | // suprascris pentru fiecare student preluat din fisier 67 | 68 | FILE* f; 69 | f = fopen("Studenti.txt", "r"); 70 | 71 | char *token, file_buf[LINESIZE], sep_list[] = ",\n"; 72 | while (fgets(file_buf, sizeof(file_buf), f)) { 73 | token = strtok(file_buf, sep_list); 74 | stud.id = atoi(token); 75 | 76 | token = strtok(NULL, sep_list); 77 | stud.nume = (char*)malloc((strlen(token) + 1) * sizeof(char)); 78 | strcpy(stud.nume, token); 79 | 80 | token = strtok(NULL, sep_list); 81 | stud.medie = (float)atof(token); 82 | 83 | token = strtok(NULL, sep_list); 84 | if (token) 85 | printf("\nEroare preluare token!"); 86 | 87 | // inserare nod la inceputul listei 88 | prim = inserareLista(prim, stud); 89 | } 90 | 91 | printf("\nLista dupa creare:\n"); 92 | parseList(prim); 93 | 94 | 95 | if (prim) // stergere student (dezalocare ultim nod) 96 | stud = stergereStudent(&prim); 97 | 98 | printf("\nLista dupa stergere student:\n"); 99 | parseList(prim); 100 | printf("Student extras: %d %s\n", stud.id, stud.nume); 101 | 102 | // dezalocare nume student extras din lista simpla 103 | free(stud.nume); 104 | 105 | // dezalocare structura lista simpla 106 | while (prim != NULL) // stergere repetata a ultimul nod pana cand lista devine empty 107 | { 108 | stud = stergereStudent(&prim); 109 | free(stud.nume); 110 | } 111 | 112 | printf("Lista dupa dezalocare:\n"); 113 | parseList(prim); 114 | 115 | fclose(f); 116 | 117 | return 0; 118 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/02_Masive.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define NR_CIFRE_CARD 16 9 | #define DIM_MONEDA 3 10 | #define DIM_VECTOR_CARDBANCAR 27 11 | 12 | struct DataExpirare 13 | { 14 | unsigned short int anul; 15 | unsigned char luna; 16 | }; 17 | 18 | typedef struct DataExpirare DataExpirare; 19 | 20 | struct CardBancar 21 | { 22 | char nr_card[NR_CIFRE_CARD + 1]; // +1 pentru terminatot de string util in cazul utilizarii ca string 23 | char* titular; 24 | DataExpirare data; 25 | float sold; 26 | char moneda[DIM_MONEDA + 1]; // RON, EUR, USD 27 | }; 28 | 29 | typedef struct CardBancar CardBancar; 30 | 31 | int main() 32 | { 33 | CardBancar v_card[DIM_VECTOR_CARDBANCAR]; 34 | CardBancar* pv_card = NULL; 35 | 36 | printf("Dimensiune vector v_card = %d\n", sizeof(v_card)); 37 | printf("Dimensiune pointer v_card = %d\n", sizeof(pv_card)); 38 | printf("Dimensiune structura CardBancar = %d\n", sizeof(CardBancar)); 39 | printf("Dimensiune structura DataExpirare = %d\n", sizeof(DataExpirare)); 40 | 41 | FILE* f = NULL; 42 | 43 | f = fopen("CarduriBancare.txt", "r"); 44 | // secventa de parsare a fisierului .txt si incarcarea datelor in vectorul v_card 45 | unsigned char i = 0; 46 | 47 | char buffer[200]; 48 | fgets(buffer, sizeof(buffer), f); 49 | 50 | while (!feof(f) && i < DIM_VECTOR_CARDBANCAR) 51 | { 52 | buffer[sizeof(v_card[i].nr_card) - 1] = 0; 53 | strtok(buffer, "\n"); 54 | strcpy(v_card[i].nr_card, buffer); 55 | 56 | fgets(buffer, sizeof(buffer), f); 57 | strtok(buffer, "\n"); 58 | v_card[i].titular = malloc(strlen(buffer) + 1); // +1 terminator de string 59 | strcpy(v_card[i].titular, buffer); 60 | 61 | fgets(buffer, sizeof(buffer), f); 62 | strtok(buffer, "\n"); 63 | sscanf(buffer, "%hu%hhu", &v_card[i].data.anul, &v_card[i].data.luna); 64 | 65 | fgets(buffer, sizeof(buffer), f); 66 | strtok(buffer, "\n"); 67 | v_card[i].sold = (float)atof(buffer); 68 | 69 | fgets(buffer, sizeof(buffer), f); 70 | strtok(buffer, "\n"); 71 | strcpy(v_card[i].moneda, buffer); 72 | 73 | i += 1; 74 | fgets(buffer, sizeof(buffer), f); 75 | } 76 | 77 | unsigned char vector_size = i; 78 | 79 | for (i = 0; i < vector_size; i++) 80 | { 81 | printf("%s %s\n", v_card[i].nr_card, v_card[i].titular); 82 | } 83 | 84 | 85 | pv_card = v_card; 86 | 87 | pv_card = malloc(vector_size * sizeof(CardBancar)); 88 | 89 | for (i = 0; i < vector_size; i++) 90 | { 91 | pv_card[i] = v_card[i]; // partajare temporara mem heap pt titular pt a copia toate elementele din v_card[i] 92 | // separare titular pe cele doua structuri prin alocare mem heap aferenta titularului din pv_card[i] 93 | pv_card[i].titular = malloc(strlen(v_card[i].titular) + 1); 94 | strcpy(pv_card[i].titular, v_card[i].titular); 95 | } 96 | 97 | // prelucrarea date carduri bancare 98 | 99 | //dezalocare pv_card 100 | for (i = 0; i < vector_size; i++) 101 | { 102 | free(pv_card[i].titular); 103 | } 104 | free(pv_card); 105 | 106 | for (i = 0; i < vector_size; i++) 107 | { 108 | free(v_card[i].titular); 109 | } 110 | 111 | // Liste simple: inserare nod in interior, stergere nod sfarsit lista simpla 112 | 113 | fclose(f); 114 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Proj/03_Structuri.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define DIM_CARD_BANCAR 16 9 | #define DIM_DATA_EXPIRARE 7 10 | #define DIM_MONEDA 3 11 | #define DIM_VECTOR_CARDBANCAR 25 12 | 13 | struct CardBancar 14 | { 15 | char nr_card[DIM_CARD_BANCAR + 1]; // +1 pentru terminator string; 20 bytes (17 + 3 padding) 16 | char* titular; // 4 bytes 17 | char data_expirare[DIM_DATA_EXPIRARE + 1]; // +1 pentru terminator string; 12 bytes (9 + 3 padding) 18 | float sold; // 4 bytes 19 | char moneda[DIM_MONEDA + 1]; // cod moneda; 4 bytes (no padding) 20 | }; 21 | 22 | typedef struct CardBancar CardBancar; 23 | 24 | int main() 25 | { 26 | CardBancar v_card[DIM_VECTOR_CARDBANCAR]; 27 | CardBancar* pv_card = NULL; 28 | printf("Dimensiune structura CardBancar = %d bytes\n", sizeof(CardBancar)); 29 | printf("Dimensiune vector v_card = %d bytes\n", sizeof(v_card)); 30 | printf("Dimensiune pointer pv_card = %d bytes\n", sizeof(pv_card)); 31 | 32 | // preluare date din fisiere pentru carduri bancare 33 | FILE* f = NULL; 34 | f = fopen("CarduriBancare.txt", "r"); 35 | 36 | char buffer[150]; 37 | char sep[] = ";\n"; 38 | unsigned char count = 0; // nr efectiv de elemente din vector 39 | fgets(buffer, sizeof(buffer), f); 40 | 41 | while (!feof(f) && count < DIM_VECTOR_CARDBANCAR) 42 | { 43 | char* token = NULL; 44 | token = strtok(buffer, sep); 45 | strcpy(v_card[count].nr_card, token); 46 | 47 | token = strtok(NULL, sep); 48 | v_card[count].titular = malloc(strlen(token) + 1); 49 | strcpy(v_card[count].titular, token); 50 | 51 | token = strtok(NULL, sep); 52 | strcpy(v_card[count].data_expirare, token); 53 | 54 | token = strtok(NULL, sep); 55 | v_card[count].sold = (float)atof(token); 56 | 57 | token = strtok(NULL, sep); 58 | strcpy(v_card[count].moneda, token); 59 | 60 | // incrementare counter (pozitie curenta in vector) 61 | count += 1; 62 | // incercare preluare linie urmatoare (daca exista) 63 | fgets(buffer, sizeof(buffer), f); 64 | } 65 | 66 | for (unsigned char i = 0; i < count; i++) 67 | { 68 | printf("%s %s\n", v_card[i].nr_card, v_card[i].titular); 69 | } 70 | 71 | pv_card = v_card; 72 | printf("\n\nCarduri bancare stocate in stack (v_card)\n"); 73 | for (unsigned char i = 0; i < count; i++) 74 | { 75 | printf("%s %s\n", pv_card[i].nr_card, pv_card[i].titular); 76 | } 77 | 78 | 79 | pv_card = malloc(count * sizeof(CardBancar)); 80 | 81 | for (unsigned char i = 0; i < count; i++) 82 | { 83 | pv_card[i] = v_card[i]; // partajare titulat intre pv_card[i] si v_card[i] 84 | 85 | // separare zone de heap pentru titular (eliminare partajare) 86 | pv_card[i].titular = malloc(strlen(v_card[i].titular) + 1); 87 | strcpy(pv_card[i].titular, v_card[i].titular); 88 | } 89 | printf("\n\nCarduri bancare stocate in heap (pv_card)\n"); 90 | for (unsigned char i = 0; i < count; i++) 91 | { 92 | printf("%s %s\n", pv_card[i].nr_card, pv_card[i].titular); 93 | } 94 | 95 | // dezalocare titulari vector stack v_card 96 | for (unsigned char i = 0; i < count; i++) 97 | free(v_card[i].titular); 98 | 99 | // dezalocare vector pv_card 100 | // pasul 1: dezalocare titulari 101 | for (unsigned char i = 0; i < count; i++) 102 | free(pv_card[i].titular); 103 | // pasul 2: dezalocare vector acrduri bancare 104 | free(pv_card); 105 | 106 | 107 | fclose(f); 108 | 109 | return 0; 110 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/04_ListaSimple.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define NR_CIFRE_CARD 16 9 | #define DIM_MONEDA 3 10 | 11 | struct DataExpirare 12 | { 13 | unsigned short int anul; 14 | unsigned char luna; 15 | }; 16 | 17 | typedef struct DataExpirare DataExpirare; 18 | 19 | struct CardBancar 20 | { 21 | char nr_card[NR_CIFRE_CARD + 1]; // +1 pentru terminatot de string util in cazul utilizarii ca string 22 | char* titular; 23 | DataExpirare data; 24 | float sold; 25 | char moneda[DIM_MONEDA + 1]; // RON, EUR, USD 26 | }; 27 | 28 | typedef struct CardBancar CardBancar; 29 | 30 | struct Nod 31 | { 32 | CardBancar card; 33 | struct Nod* next; 34 | }; 35 | 36 | typedef struct Nod Nod; 37 | 38 | // inserare nod la sfarsitul listei simple 39 | Nod* inserare_sfarsit(Nod* lista , CardBancar data) 40 | { 41 | Nod* nou = malloc(sizeof(Nod)); 42 | nou->card = data; 43 | nou->next = NULL; 44 | 45 | if (lista == NULL) 46 | { 47 | return nou; // nou devine primul si unicul si ultimul din lista simpla 48 | } 49 | else 50 | { 51 | Nod* temp = lista; 52 | while (temp->next != NULL) 53 | { 54 | temp = temp->next; // temp rescris cu adresa succesorului curent 55 | } 56 | 57 | // temp este ultimul nod din lista simpla 58 | temp->next = nou; // atasare nou la sfarsitul listei simple 59 | } 60 | return lista; 61 | } 62 | 63 | // traversare lista simpla 64 | void traversare_listasimpla(Nod* lista) 65 | { 66 | Nod* temp = lista; 67 | while (temp != NULL) 68 | { 69 | printf("%s %s\n", temp->card.nr_card, temp->card.titular); 70 | temp = temp->next; 71 | } 72 | } 73 | 74 | // stergere nod la inceputul listei simple 75 | Nod* stergere_inceput(Nod* lista) 76 | { 77 | if (lista != NULL) 78 | { 79 | // exista cel putin un nod in lista simpla 80 | Nod* temp = lista; // salvare temporara a primului nod in temp 81 | lista = lista->next; // actualizare inceput de lista simpla 82 | 83 | free(temp->card.titular); // dezalocare mem heap alocata pt pointer titular 84 | free(temp); // dezalocare mem heap pentru inceputul de lista simpla 85 | } 86 | 87 | return lista; // returneaza noul inceput de lista 88 | } 89 | 90 | int main() 91 | { 92 | FILE* f = NULL; 93 | f = fopen("CarduriBancare.txt", "r"); 94 | 95 | char buffer[200]; 96 | CardBancar card; 97 | Nod* prim = NULL; // variabila locala acces la primul element din lista simpla 98 | 99 | fgets(buffer, sizeof(buffer), f); 100 | while (!feof(f)) 101 | { 102 | buffer[sizeof(card.nr_card) - 1] = 0; 103 | strtok(buffer, "\n"); 104 | strcpy(card.nr_card, buffer); 105 | 106 | fgets(buffer, sizeof(buffer), f); 107 | strtok(buffer, "\n"); 108 | card.titular = malloc(strlen(buffer) + 1); // +1 terminator de string 109 | strcpy(card.titular, buffer); 110 | 111 | fgets(buffer, sizeof(buffer), f); 112 | strtok(buffer, "\n"); 113 | sscanf(buffer, "%hu%hhu", &card.data.anul, &card.data.luna); 114 | 115 | fgets(buffer, sizeof(buffer), f); 116 | strtok(buffer, "\n"); 117 | card.sold = (float)atof(buffer); 118 | 119 | fgets(buffer, sizeof(buffer), f); 120 | strtok(buffer, "\n"); 121 | strcpy(card.moneda, buffer); 122 | 123 | // inserare date card bancar in lista simpla 124 | prim = inserare_sfarsit(prim, card); 125 | 126 | fgets(buffer, sizeof(buffer), f); 127 | } 128 | fclose(f); 129 | 130 | printf("Lista simpla dupa creare:\n"); 131 | traversare_listasimpla(prim); 132 | 133 | prim = stergere_inceput(prim); 134 | printf("\n\nLista simpla dupa stergerea unui nod:\n"); 135 | traversare_listasimpla(prim); 136 | 137 | while (prim != NULL) 138 | { 139 | prim = stergere_inceput(prim); 140 | } 141 | printf("\n\nLista simpla dupa dezalocare:\n"); 142 | traversare_listasimpla(prim); 143 | 144 | return 0; 145 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/04_ListeSimple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define CARD_NO_LENGTH 16 6 | #define MONEDA_COD_LENGTH 3 7 | 8 | struct CardBancar 9 | { 10 | char nr_card[CARD_NO_LENGTH + 1]; 11 | char* detinator; 12 | char expira_la[6]; 13 | float sold; 14 | char moneda[MONEDA_COD_LENGTH + 1]; 15 | }; 16 | 17 | typedef struct CardBancar CardBancar; 18 | 19 | struct Nod 20 | { 21 | CardBancar card; 22 | struct Nod* next; 23 | }; 24 | typedef struct Nod Nod; 25 | 26 | 27 | // operatii de baza liste simple: inserare nod inceput, inserare nod sfarsit, stergere nod sfarsit, stergere nod din interior 28 | 29 | // functie de inserare nod la inceputul listei simple 30 | Nod* inserare_inceput(Nod* lista, CardBancar data) 31 | { 32 | Nod* nou = malloc(sizeof(Nod)); // alocare nod nou pentru preluarea datelor din param data 33 | nou->card = data; // salvare date din data (card bancar) in Nod nou 34 | nou->next = lista; // succesorului lui nou va fi actual inceput de lista simpla (lista) 35 | 36 | return nou; // se returneaza noua adresa de inceput 37 | } 38 | 39 | // functie de traversare lista simpla 40 | void traversare_listasimpla(Nod* lista) 41 | { 42 | Nod* temp = lista; 43 | while (temp != NULL) 44 | { 45 | printf("%s %s\n", temp->card.nr_card, temp->card.detinator); 46 | 47 | temp = temp->next; // actualizare pointer temp catre succesor al actualului temp 48 | } 49 | } 50 | 51 | // functie de stergere nod la sfarsitul listei simple 52 | Nod* stergere_sfarsit(Nod* lista) 53 | { 54 | if (lista->next == NULL) 55 | { 56 | // lista simpla contine 1 singur nod 57 | free(lista->card.detinator); //dezalocare pointer detinator din card bancar 58 | free(lista); // dezalocarea primului si unicului nod din lista simpla 59 | lista = NULL; 60 | } 61 | else 62 | { 63 | Nod* pred, * temp; 64 | pred = lista; // pred primul nod din lista 65 | temp = lista->next; // temp nodul 2 din lista 66 | while (temp->next != NULL) // exista nod succesor pt temp; temp nu este ultimul nod din lista 67 | { 68 | pred = temp; 69 | temp = temp->next; 70 | } 71 | 72 | // temp este ultimul nod, pred este penultimul nod 73 | free(temp->card.detinator); 74 | free(temp); 75 | 76 | pred->next = NULL; 77 | } 78 | 79 | return lista; 80 | } 81 | 82 | 83 | int main() 84 | { 85 | FILE* f; // pointer la structura FILE (handler de fisier) 86 | Nod* prim = NULL; // initializare lista simpla cu NULL -> lista empty (0 noduri) 87 | 88 | f = fopen("CarduriBancare.txt", "r"); 89 | 90 | char titular[150]; 91 | CardBancar card; 92 | fscanf(f, "%[^,],%[^,],%[^,],%f,%[^\n]", card.nr_card, titular, 93 | card.expira_la, &(card.sold), card.moneda); 94 | while (!feof(f)) // 1. conditie aplicata dupa o incercare de a citi nr card bancar 95 | { 96 | card.detinator = malloc(strlen(titular) + 1); // +1 pt terminatorul de string (byte 0x00) 97 | strcpy(card.detinator, titular); // copiere string nume detinator in variabila temporara card 98 | 99 | fscanf(f, "\n"); 100 | 101 | // inserare in lista simpla card bancar "pregatit" in variabila temporara card 102 | prim = inserare_inceput(prim, card); 103 | 104 | fscanf(f, "%[^,],%[^,],%[^,],%f,%[^\n]", card.nr_card, titular, 105 | card.expira_la, &(card.sold), card.moneda); // citire nr card de pe linia urmatoare 106 | } 107 | fclose(f); 108 | printf("Lista simpla dupa creare:\n"); 109 | traversare_listasimpla(prim); 110 | // stergere nod la sfarsitul listei simple 111 | prim = stergere_sfarsit(prim); 112 | printf("\n\nLista simpla dupa stergerea ultimului nod:\n"); 113 | traversare_listasimpla(prim); 114 | 115 | // dezalocare structura lista simpla 116 | while (prim != NULL) 117 | { 118 | prim = stergere_sfarsit(prim); 119 | } 120 | 121 | printf("\n\nLista simpla dupa dezalocarea listei simple:\n"); 122 | traversare_listasimpla(prim); 123 | 124 | return 0; 125 | } 126 | -------------------------------------------------------------------------------- /2024-2025/Grupa1076Sol/Grupa1076Proj/03_Structures.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define CARD_NUMBER_LENGTH 16 8 | #define EXPIRING_DATE_FORMAT_LENGTH 5 // MM/YY 9 | #define CARD_ARRAYS_LENGTH 20 10 | 11 | struct BankCard 12 | { 13 | char* holder; // 4 bytes 14 | char card_no[CARD_NUMBER_LENGTH + 1];// +1 for null terminator byte; 17 bytes 15 | float balance; // 4 bytes 16 | char exp_date[EXPIRING_DATE_FORMAT_LENGTH + 1]; // +1 for null terminator byte; 6 bytes 17 | char* currency; // 4 bytes 18 | }; // 35 bytes ?! -> 40 bytes 19 | 20 | typedef struct BankCard BankCard; 21 | 22 | int main() 23 | { 24 | BankCard v_card[CARD_ARRAYS_LENGTH]; 25 | BankCard* p_card = NULL; 26 | printf("Size of the structure BankCard is = %d bytes\n", sizeof(BankCard)); 27 | printf("Size of the array v_card is = %d bytes\n", sizeof(v_card)); 28 | printf("Size of the pointer p_card is = %d bytes\n", sizeof(p_card)); 29 | 30 | FILE* f = fopen("CardData.txt", "r"); 31 | 32 | unsigned char count = 0; 33 | unsigned char buffer[200]; 34 | while (fgets(buffer, sizeof(buffer), f) && count < CARD_ARRAYS_LENGTH) 35 | { 36 | char seps[] = ",\n"; 37 | char* token = strtok(buffer, seps); 38 | strcpy(v_card[count].card_no, token); 39 | 40 | token = strtok(NULL, seps); // continue the splitting 41 | strcpy(v_card[count].exp_date, token); 42 | 43 | token = strtok(NULL, seps); 44 | v_card[count].holder = malloc(strlen(token) + 1); 45 | strcpy(v_card[count].holder, token); 46 | 47 | token = strtok(NULL, seps); 48 | v_card[count].currency = malloc(strlen(token) + 1); 49 | strcpy(v_card[count].currency, token); 50 | 51 | token = strtok(NULL, seps); 52 | v_card[count].balance = (float)atof(token); 53 | 54 | count += 1; // the next offset to be considered for the next line in the text file 55 | } 56 | 57 | fclose(f); 58 | 59 | printf("Card data from v_card array:\n"); 60 | for (unsigned char i = 0; i < count; i++) 61 | { 62 | printf("%s %s\n", v_card[i].card_no, v_card[i].holder); 63 | } 64 | 65 | p_card = v_card; 66 | printf("\nCard data from v_card array by using p_card pointer:\n"); 67 | for (unsigned char i = 0; i < count; i++) 68 | { 69 | printf("%s %s\n", p_card[i].card_no, p_card[i].holder); 70 | } 71 | 72 | p_card = malloc(count * sizeof(BankCard)); 73 | for (unsigned char i = 0; i < count; i++) 74 | { 75 | p_card[i] = v_card[i]; // v_card and p_card share the same heap mem areas for holder and currency 76 | // create separate hep mem locations for p_card 77 | p_card[i].holder = malloc(strlen(v_card[i].holder) + 1); 78 | strcpy(p_card[i].holder, v_card[i].holder); 79 | p_card[i].currency = malloc(strlen(v_card[i].currency) + 1); 80 | strcpy(p_card[i].currency, v_card[i].currency); 81 | } 82 | 83 | printf("\nCard data from p_card array in heap mem:\n"); 84 | for (unsigned char i = 0; i < count; i++) 85 | { 86 | printf("%s %s\n", p_card[i].card_no, p_card[i].holder); 87 | } 88 | 89 | v_card[0].holder[0] = 'X'; 90 | printf("\nArrays after changing the holder's first letter of the first item\n"); 91 | printf("Card data from v_card array after change:\n"); 92 | for (unsigned char i = 0; i < count; i++) 93 | { 94 | printf("%s %s\n", v_card[i].card_no, v_card[i].holder); 95 | } 96 | printf("\nCard data from p_card array in heap mem after change:\n"); 97 | for (unsigned char i = 0; i < count; i++) 98 | { 99 | printf("%s %s\n", p_card[i].card_no, p_card[i].holder); 100 | } 101 | 102 | // deallocations of arrays 103 | // v_card allocated on stack seg 104 | for (unsigned char i = 0; i < count; i++) 105 | { 106 | free(v_card[i].holder); 107 | free(v_card[i].currency); 108 | } 109 | 110 | // p_card allocated onm heap seg 111 | // step 1: deallocate holder and currency 112 | for (unsigned char i = 0; i < count; i++) 113 | { 114 | free(p_card[i].holder); 115 | free(p_card[i].currency); 116 | } 117 | // step 2: deallocate the array of cards 118 | free(p_card); 119 | 120 | 121 | return 0; 122 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/10_StructHeap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define CAPACITATE_STOCARE_HEAP 8 5 | 6 | 7 | int* realocare_vector_heap(int* heap, unsigned char *capacitate, unsigned char plus_elem) 8 | { 9 | unsigned char nr_chei = *capacitate; // nr de chei continute de heap 10 | *capacitate += plus_elem; // crestere capacitate de stocare pt heap 11 | 12 | int* new_heap = malloc(*capacitate * sizeof(int)); // alocare nou vector pentru heap cu capacitate marita 13 | 14 | for (unsigned char i = 0; i < nr_chei; i++) // salvare elemente heap pe noua structura heap (mai mare) 15 | new_heap[i] = heap[i]; 16 | 17 | free(heap); // dezalocare structura curenta heap 18 | 19 | return new_heap; // return noua structura heap 20 | } 21 | 22 | int* agregare_struct_heap(int* h1, unsigned char size_h1, 23 | int* h2, unsigned char size_h2, 24 | int* h_rez, unsigned char *size_hrez, 25 | unsigned char* capacitate, int cheie_noua) 26 | { 27 | h_rez = malloc(*capacitate * sizeof(int)); 28 | h_rez[0] = cheie_noua; // inserare cheie noua in heap agregat 29 | *size_hrez = 1; // actualizare nr chei din heap agregat 30 | 31 | if (size_h1 < size_h2) 32 | { 33 | // structura heap2 este mai mare (nr chei si implicit inaltime) decat structura heap1 34 | // agregarea se efectueaza pe heap1 mai inalt decat heap2 35 | 36 | // se interschimba cele doua structuri heap (input pentru structura agregata) 37 | int* paux = h1; 38 | h1 = h2; 39 | h2 = paux; 40 | 41 | unsigned char saux = size_h1; 42 | size_h1 = size_h2; 43 | size_h2 = saux; 44 | } 45 | 46 | unsigned char i = 0; // offset traversare h1 47 | unsigned char j = 0; // offset traversare h2 48 | 49 | unsigned char nr_chei_hcurent = 1; // nr de chei de pe nivel curent care se salveaza in heap agregat 50 | unsigned char l = 0; // nr chei salvate anterior in heap agregat 51 | 52 | unsigned char gata = 1; 53 | 54 | // 1. agregarea este corecta doar pentru o diferenta de inaltime de maxim 1 nivel 55 | // in caz contrar, structura agregata trebuie validata si prelucrata astfel incat sa fie un arbore binar complet 56 | // 2. daca structurile heap1 si heap2 au acelasi numar de niveluri, se valideaza ca heap 1 are ultimul nivel complet 57 | while (gata == 1) // asigura traversarea pe niveluri in tandem pentru h1 si h2 58 | { 59 | l = i; // numar de elemente salvate anterior in structura agregata 60 | // salvare chei de pe nivel curent din h1 61 | for (; i < size_h1 && i < l + nr_chei_hcurent; i++) 62 | { 63 | h_rez[*size_hrez] = h1[i]; 64 | *size_hrez += 1; 65 | if (*size_hrez == *capacitate) 66 | { 67 | h_rez = realocare_vector_heap(h_rez, capacitate, CAPACITATE_STOCARE_HEAP); 68 | } 69 | } 70 | 71 | // salvare chei de pe nivel curent din h2 72 | for (; j < size_h2 && j < l + nr_chei_hcurent; j++) 73 | { 74 | h_rez[*size_hrez] = h2[j]; 75 | *size_hrez += 1; 76 | if (*size_hrez == *capacitate) 77 | { 78 | h_rez = realocare_vector_heap(h_rez, capacitate, CAPACITATE_STOCARE_HEAP); 79 | } 80 | } 81 | 82 | if (i == size_h1 && j == size_h2) // este suficient i == size_h1 deoarece h1 este intotdeauna mai mare decat h2 83 | { 84 | gata = 0; // ambele structuri au fost salvate in heap agregat 85 | } 86 | 87 | nr_chei_hcurent = nr_chei_hcurent * 2; // calcul nr de chei de pe nivelul urmator 88 | } 89 | 90 | return h_rez; 91 | } 92 | 93 | int main() 94 | { 95 | int heap1[] = {32, 12, 24, 7, 9, 17}; 96 | int heap2[] = {8, 2, 3}; 97 | 98 | int *heap_agregat = NULL; 99 | unsigned char capacitate_stocare, nr_chei; 100 | 101 | capacitate_stocare = CAPACITATE_STOCARE_HEAP; // capacitatea de stocare initiala 102 | heap_agregat = agregare_struct_heap(heap1, sizeof(heap1) / sizeof(int), 103 | heap2, sizeof(heap2) / sizeof(int), 104 | heap_agregat, &nr_chei, &capacitate_stocare, 23); 105 | 106 | printf("Structura Heap agregata si nevalidata: "); 107 | for (unsigned char i = 0; i < nr_chei; i++) 108 | printf("%d ", heap_agregat[i]); 109 | printf("\n"); 110 | 111 | // validare pozitie cheie din nod radacina 112 | // se cauta prin abordare top-down locul corect al cheii inserate 113 | // vezi suport de curs, operatia de stergere 114 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/03_Structuri.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define DIM_NR_CARD 16 9 | #define DIM_DATA_EXPIRARE 5 10 | #define NR_ELEMENTE_VECTOR 30 11 | 12 | struct CardBancar 13 | { 14 | char* titular; // 4 bytes 15 | char nr_card[DIM_NR_CARD + 1]; // +1 pt byte terminator de string; 20 bytes (17 + 3 padding) 16 | float sold; // 4 bytes 17 | char* emitent; // 4 bytes 18 | char data_expirare[DIM_DATA_EXPIRARE + 1]; // LL/AA; 8 bytes (6 + 2 padding) 19 | }; 20 | 21 | typedef struct CardBancar CardBancar; 22 | 23 | int main() 24 | { 25 | CardBancar v_card[NR_ELEMENTE_VECTOR]; 26 | CardBancar *pv_card = NULL; 27 | 28 | printf("Dimensiune vector v_card = %d\n", sizeof(v_card)); 29 | printf("Dimensiune structura CardBancar= %d\n", sizeof(CardBancar)); 30 | printf("Dimensiune pointer pv_card = %d\n", sizeof(pv_card)); 31 | 32 | // exemplu de populare a vectorului v_card cu date din fisier 33 | 34 | FILE* f = NULL; 35 | f = fopen("CarduriBancare.txt", "r"); 36 | 37 | unsigned char count = 0; // nr efectiv de elemente din vectorul v_card 38 | char temp_buff[100]; // buffer temporar pentru stocare linii preluate din fisier text 39 | fgets(temp_buff, sizeof(temp_buff), f); 40 | 41 | while (!feof(f) && count < NR_ELEMENTE_VECTOR) // exista card bancar de preluat SI vectorul are spatiu pt stocarea sa 42 | { 43 | strtok(temp_buff, "\n"); 44 | v_card[count].titular = malloc(strlen(temp_buff) + 1); // alocare mem heap titular element count 45 | strcpy(v_card[count].titular, temp_buff); // copiere continut titular din buffer in vector pe element count 46 | 47 | fgets(temp_buff, sizeof(temp_buff), f); 48 | strtok(temp_buff, "\n"); 49 | strcpy(v_card[count].nr_card, temp_buff); 50 | 51 | fgets(temp_buff, sizeof(temp_buff), f); 52 | strtok(temp_buff, "\n"); 53 | v_card[count].sold = (float)atof(temp_buff); // conversie ASCII-to-Binary pentru float 54 | 55 | fgets(temp_buff, sizeof(temp_buff), f); 56 | strtok(temp_buff, "\n"); 57 | v_card[count].emitent = malloc(strlen(temp_buff) + 1); // alocare mem heap pentru emitent element count 58 | strcpy(v_card[count].emitent, temp_buff); // copiere emitent din buffer in emitent element count din vector 59 | 60 | fgets(temp_buff, sizeof(temp_buff), f); 61 | strtok(temp_buff, "\n"); 62 | strcpy(v_card[count].data_expirare, temp_buff); 63 | 64 | // incrementare element curent in vector 65 | count += 1; 66 | // incercare preluare titular card urmator 67 | fgets(temp_buff, sizeof(temp_buff), f); 68 | } 69 | 70 | for (unsigned char i = 0; i < count; i++) 71 | { 72 | printf("%s %s\n", v_card[i].titular, v_card[i].nr_card); 73 | } 74 | printf("\n\n"); 75 | pv_card = v_card; 76 | for (unsigned char i = 0; i < count; i++) 77 | { 78 | printf("%s %s\n", pv_card[i].titular, pv_card[i].nr_card); // aceleasi locatii ca v_card 79 | } 80 | 81 | // pv_card alocat in mem heap 82 | pv_card = malloc(count * sizeof(CardBancar)); 83 | for (unsigned char i = 0; i < count; i++) 84 | { 85 | pv_card[i] = v_card[i]; // temporar asumata partajarea de zone heap pentru titular si emitent 86 | 87 | // alocare si populare zone separate de heap pentru titular si emitent 88 | pv_card[i].titular = malloc(strlen(v_card[i].titular) + 1); 89 | strcpy(pv_card[i].titular, v_card[i].titular); 90 | 91 | pv_card[i].emitent = malloc(strlen(v_card[i].emitent) + 1); 92 | strcpy(pv_card[i].emitent, v_card[i].emitent); 93 | } 94 | 95 | printf("\n\nCarduri bancare stocate in heap\n"); 96 | for (unsigned char i = 0; i < count; i++) 97 | { 98 | printf("%s %s\n", pv_card[i].titular, pv_card[i].nr_card); // aceleasi locatii ca v_card 99 | } 100 | 101 | // dezalocare vectori de structuri CardBancar 102 | for (unsigned char i = 0; i < count; i++) 103 | { 104 | free(v_card[i].titular); 105 | free(v_card[i].emitent); 106 | } 107 | 108 | // pasul 1: dezalocarea zonelor cele mai indepartate (string-uri titular si emitent) 109 | for (unsigned char i = 0; i < count; i++) 110 | { 111 | free(pv_card[i].titular); 112 | free(pv_card[i].emitent); 113 | } 114 | //pasul 2: dezalocare vectorului de elemente CardBancar 115 | free(pv_card); 116 | 117 | fclose(f); 118 | return 0; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/04_ListeSimple.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define DIM_NR_CARD 16 9 | #define DIM_DATA_EXPIRARE 5 10 | 11 | struct CardBancar 12 | { 13 | char* titular; // 4 bytes 14 | char nr_card[DIM_NR_CARD + 1]; // +1 pt byte terminator de string; 20 bytes (17 + 3 padding) 15 | float sold; // 4 bytes 16 | char* emitent; // 4 bytes 17 | char data_expirare[DIM_DATA_EXPIRARE + 1]; // LL/AA; 8 bytes (6 + 2 padding) 18 | }; 19 | 20 | typedef struct CardBancar CardBancar; 21 | 22 | struct Nod 23 | { 24 | CardBancar cb; 25 | struct Nod* next; 26 | }; 27 | 28 | typedef struct Nod Nod; 29 | 30 | Nod* inserare_nod_sfarsit(Nod* lista, CardBancar data) 31 | { 32 | // alocare nod 33 | Nod* nou = malloc(sizeof(Nod)); 34 | 35 | // populare nod cu data 36 | nou->cb = data; // partajare temporara mem heap pt titular si emitent 37 | nou->next = NULL; // nu exista succesor; nou va deveni ultimul nod in lista simpla 38 | 39 | if (lista == NULL) 40 | { 41 | // nu exista nici un nod in lista simpla 42 | return nou; 43 | // lista = nou; // lista se returneaza la finalul executiei functiei 44 | } 45 | else 46 | { 47 | // exista cel putin un nod in lista simpla 48 | // cautare sfarsit de lista 49 | Nod* temp = lista; 50 | while (temp->next != NULL) 51 | temp = temp->next; // actualizez temp pe nodul succesor 52 | 53 | // temp este plasat pe ultimul nod din lista simpla 54 | temp->next = nou; // legarea/atasarea lui nou la sfarsitul listei simple 55 | 56 | } 57 | // return lista actualizata daca este cazul 58 | return lista; 59 | } 60 | 61 | void traversare_listasimpla(Nod* lista) 62 | { 63 | Nod* temp = lista; 64 | while (temp) 65 | { 66 | printf("%s %s\n", temp->cb.nr_card, temp->cb.titular); 67 | temp = temp->next; 68 | } 69 | } 70 | 71 | Nod* stergere_inceput(Nod* lista) 72 | { 73 | if (lista != NULL) 74 | { 75 | // exista cel putin 1 nod in lista simpla 76 | Nod* temp = lista; 77 | lista = lista->next; // actualizare inceput de lista pe nodul 2 (succesor) 78 | 79 | free(temp->cb.emitent); // dezalocare extensie in heap pentru CardBancar 80 | free(temp->cb.titular); // dezalocare extensie in heap pentru CardBancar 81 | 82 | free(temp); // dezalocare nod 83 | } 84 | 85 | return lista; 86 | } 87 | 88 | int main() 89 | { 90 | FILE* f = NULL; 91 | f = fopen("CarduriBancare.txt", "r"); 92 | 93 | CardBancar card; 94 | Nod* prim = NULL; // variabila pointer acces la lista simpla 95 | 96 | char temp_buff[100]; // buffer temporar pentru stocare linii preluate din fisier text 97 | fgets(temp_buff, sizeof(temp_buff), f); 98 | 99 | while (!feof(f)) 100 | { 101 | strtok(temp_buff, "\n"); 102 | card.titular = malloc(strlen(temp_buff) + 1); 103 | strcpy(card.titular, temp_buff); 104 | 105 | fgets(temp_buff, sizeof(temp_buff), f); 106 | strtok(temp_buff, "\n"); 107 | strcpy(card.nr_card, temp_buff); 108 | 109 | fgets(temp_buff, sizeof(temp_buff), f); 110 | strtok(temp_buff, "\n"); 111 | card.sold = (float)atof(temp_buff); // conversie ASCII-to-Binary pentru float 112 | 113 | fgets(temp_buff, sizeof(temp_buff), f); 114 | strtok(temp_buff, "\n"); 115 | card.emitent = malloc(strlen(temp_buff) + 1); 116 | strcpy(card.emitent, temp_buff); 117 | 118 | fgets(temp_buff, sizeof(temp_buff), f); 119 | strtok(temp_buff, "\n"); 120 | strcpy(card.data_expirare, temp_buff); 121 | 122 | // inserare date card in lista simpla 123 | prim = inserare_nod_sfarsit(prim, card); 124 | 125 | // incercare preluare titular card urmator 126 | fgets(temp_buff, sizeof(temp_buff), f); 127 | } 128 | fclose(f); 129 | 130 | printf("Lista simpla dupa creare:\n"); 131 | traversare_listasimpla(prim); 132 | 133 | // stergere nod la inceput 134 | prim = stergere_inceput(prim); 135 | printf("\n\nLista simpla dupa stergere nod la inceput:\n"); 136 | traversare_listasimpla(prim); 137 | 138 | // dezalocare lista simpla 139 | while (prim != NULL) 140 | { 141 | // exista cel putin un nod in lista simpla 142 | // care poate fi sters/eliminat din lista 143 | prim = stergere_inceput(prim); 144 | } 145 | 146 | printf("\n\nLista simpla dupa dezalocare:\n"); 147 | traversare_listasimpla(prim); 148 | 149 | // stergere la interior (criteriu definit) 150 | 151 | return 0; 152 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Proj/10_StructHeapc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define CAPACITATE_STOCARE_HEAP 7 5 | 6 | int* realocare_vector_heap(int* h_rezultat, unsigned char* capacitate, unsigned char capacitate_suplimentara) 7 | { 8 | unsigned char nr_chei = *capacitate; // nr chei identic cu capacitate 9 | *capacitate = *capacitate + capacitate_suplimentara; // marire capacitate maxima de stocare a vectorului 10 | 11 | int* new_vector_heap = malloc(*capacitate * sizeof(int)); // alocare vector nou pe capacitate noua 12 | 13 | // mutare elemente pe noul vector 14 | for (unsigned char i = 0; i < nr_chei; i++) 15 | { 16 | new_vector_heap[i] = h_rezultat[i]; 17 | } 18 | 19 | free(h_rezultat); // vectorul curent este dezalocat 20 | 21 | return new_vector_heap; // adresa noului vector suport pentru heap agregat 22 | } 23 | 24 | int* agregare_structuri_heap(int* h1, unsigned char dim_h1, 25 | int* h2, unsigned char dim_h2, 26 | unsigned char* capacitate, unsigned char* nr_chei, 27 | int cheie_inserata) 28 | { 29 | int* h_rezultat = malloc(*capacitate * sizeof(int)); 30 | h_rezultat[0] = cheie_inserata; // cheia noua se aseaza pe radacina de structura heap agregata 31 | 32 | *nr_chei = 1; 33 | 34 | if (dim_h1 < dim_h2) 35 | { 36 | // structura h2 este mai mare (eventual cu inaltime mai mare) 37 | // interschimb adresa astfel incat h1 este intotdeauna mai mare (eventual mai inalt) 38 | 39 | int* paux = h1; 40 | h1 = h2; 41 | h2 = paux; 42 | 43 | // se interschimba si dimensiunile pentru accesarea corecta a elementelor din vectorii interschimbati mai sus 44 | unsigned char daux = dim_h1; 45 | dim_h1 = dim_h2; 46 | dim_h2 = daux; 47 | } 48 | 49 | unsigned char flag = 1; // flag determinare momemnt finalizare operatie de salvare a cheilor din h1 si h2 in struct agregata 50 | unsigned char i = 0; // offset traversare h1 51 | unsigned char j = 0; // offset traversare h2 52 | unsigned int nr_chei_nivel_curent = 1; // nr maxim de chei de pe nivel curent 53 | 54 | // 1. Diferenta de inaltime dintre h1 si h2 este de maxim 1 nivel; altfel, structura heap agregata trebuie 55 | // sa fie restructurata astfel incat sa respecte asezarea nodurilor ca arbore binar complet 56 | // 2. Daca h1 si h2 au aceeasi inaltime, se valideaza ca h1 sa aiba ultimul nivel complet ocupat cu noduri 57 | 58 | while (flag == 1) // traversare structuri h1 si h2 pe niveluri in tandem 59 | { 60 | // fiecare iteratie de while acceseaza acelasi nivel din h1 si h2 61 | unsigned char l = i; // numar de chei salvate in structura agregata de pe nivelurile superioare 62 | for (; i < dim_h1 && i < nr_chei_nivel_curent + l; i++) 63 | { 64 | h_rezultat[*nr_chei] = h1[i]; 65 | *nr_chei += 1; 66 | 67 | if (*nr_chei == *capacitate) 68 | { 69 | // nu mai exista spatiu pentru salvare de chei in heap agregat 70 | h_rezultat = realocare_vector_heap(h_rezultat, capacitate, CAPACITATE_STOCARE_HEAP); 71 | } 72 | } 73 | 74 | for (; j < dim_h2 && j < nr_chei_nivel_curent + l; j++) 75 | { 76 | h_rezultat[*nr_chei] = h2[j]; 77 | *nr_chei += 1; 78 | 79 | if (*nr_chei == *capacitate) 80 | { 81 | // nu mai exista spatiu pentru salvare de chei in heap agregat 82 | h_rezultat = realocare_vector_heap(h_rezultat, capacitate, CAPACITATE_STOCARE_HEAP); 83 | } 84 | } 85 | 86 | if (i == dim_h1 && j == dim_h2) // suficienta validarea doar cu i deoarece dim_h2 <= dim_h1 87 | { 88 | flag = 0; 89 | } 90 | 91 | nr_chei_nivel_curent = nr_chei_nivel_curent * 2; // numar maxim de chei de pe nivel inferior 92 | } 93 | 94 | return h_rezultat; 95 | } 96 | 97 | int main() 98 | { 99 | int heap1[] = {32, 12, 24, 7, 9, 17}; 100 | int heap2[] = {8, 2, 3}; 101 | 102 | int* heap_agregat = NULL; 103 | unsigned char capacitate, nr_chei; 104 | 105 | capacitate = CAPACITATE_STOCARE_HEAP; 106 | 107 | heap_agregat = agregare_structuri_heap(heap1, sizeof(heap1)/sizeof(int), 108 | heap2, sizeof(heap2)/sizeof(int), 109 | &capacitate, &nr_chei, 23); 110 | 111 | printf("Structura Heap dupa agregare, dar nevalidata: "); 112 | for (unsigned char i = 0; i < nr_chei; i++) 113 | printf("%d ", heap_agregat[i]); 114 | printf("\n"); 115 | 116 | // validare pozitie cheie inserata (23) in arborele Heap 117 | // prin aplicarea operatiei de filtrare top-down 118 | // vezi suport curs, operatia de stergere 119 | 120 | return 0; 121 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/11_ArbBin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define CARD_NO_LENGTH 16 7 | #define MONEDA_COD_LENGTH 3 8 | 9 | struct CardBancar 10 | { 11 | char nr_card[CARD_NO_LENGTH + 1]; 12 | char* detinator; 13 | char expira_la[6]; 14 | float sold; 15 | char moneda[MONEDA_COD_LENGTH + 1]; 16 | }; 17 | 18 | typedef struct CardBancar CardBancar; 19 | 20 | struct NodArb { 21 | CardBancar data; 22 | struct NodArb* st, * dr; 23 | }; 24 | 25 | typedef struct NodArb NodArb; 26 | 27 | NodArb* inserare_nod_ABC(NodArb* r, CardBancar data, unsigned char *inserat) 28 | { 29 | // verificare cheie de inserat cu cheie nod curent (r) pentru a continua cautarea 30 | // pe subarbore stanga sau dreapta 31 | if (r != NULL) 32 | { 33 | if (strcmp(data.nr_card, r->data.nr_card) < 0) 34 | { 35 | // cautarea locului de inserat continua pe subarbore stanga 36 | r->st = inserare_nod_ABC(r->st, data, inserat); 37 | } 38 | else 39 | { 40 | if (strcmp(data.nr_card, r->data.nr_card) > 0) 41 | { 42 | // cautarea locului de inserat continua pe subarbore dreapta 43 | r->dr = inserare_nod_ABC(r->dr, data, inserat); 44 | } 45 | else { 46 | // stringuri identice 47 | *inserat = 1; // comutare flag cheie existenta in ABC. se abandoneaza cautarea locului de inserat 48 | return r; 49 | } 50 | } 51 | } 52 | else 53 | { 54 | // r == NULL 55 | // am identificat locul de inserat pentru setul data 56 | 57 | r = malloc(sizeof(NodArb)); // alocare nod ABC 58 | 59 | r->data = data; 60 | r->st = NULL; 61 | r->dr = NULL; 62 | 63 | *inserat = 0; // inserare cu succes pentru datele primite in parametrul data 64 | } 65 | 66 | return r; 67 | } 68 | 69 | 70 | void traversare_Inordine_ABC(NodArb* r) 71 | { 72 | if (r != NULL) 73 | { 74 | traversare_Inordine_ABC(r->st); 75 | printf("%s\n", r->data.nr_card); 76 | traversare_Inordine_ABC(r->dr); 77 | } 78 | } 79 | 80 | NodArb* stergere_nod_ABC(NodArb* r, char* cheie, unsigned char* flag_stergere) 81 | { 82 | if (r != NULL) 83 | { 84 | if (strcmp(cheie, r->data.nr_card) < 0) 85 | { 86 | // cautarea locului de inserat continua pe subarbore stanga 87 | r->st = stergere_nod_ABC(r->st, cheie, flag_stergere); 88 | } 89 | else 90 | { 91 | if (strcmp(cheie, r->data.nr_card) > 0) 92 | { 93 | // cautarea locului de inserat continua pe subarbore dreapta 94 | r->dr = stergere_nod_ABC(r->dr, cheie, flag_stergere); 95 | } 96 | else { 97 | // stringuri identice 98 | // r este nodul care se sterge din ABC 99 | *flag_stergere = 1; // comutare flag cheie existenta in ABC. se sterge nodul r 100 | 101 | // operatie de stergere pentru cele 3 cazuri: 0, 1 sau 2 descendenti 102 | } 103 | } 104 | } 105 | else 106 | { 107 | // r == NULL 108 | // nu exista nod de sters in ABC 109 | *flag_stergere = 0; 110 | } 111 | 112 | return r; 113 | } 114 | 115 | // dezalocare ABC 116 | 117 | // determinare inaltime ABC 118 | 119 | // identificare carduri bancare plasate pe un nivel specificat in ABC 120 | 121 | int main() 122 | { 123 | NodArb* root = NULL; // variabila pointer la nod radacina cu care accesez tot arborele binar de cautare 124 | 125 | char titular[150]; 126 | CardBancar card; 127 | FILE* f = fopen("CarduriBancare.txt", "r"); 128 | fscanf(f, "%[^,],%[^,],%[^,],%f,%[^\n]", card.nr_card, titular, 129 | card.expira_la, &(card.sold), card.moneda); 130 | 131 | while (!feof(f)) 132 | { 133 | card.detinator = malloc(strlen(titular) + 1); 134 | strcpy(card.detinator, titular); 135 | 136 | fscanf(f, "\n"); 137 | 138 | // inserare date card bancar (card) in arbore binar de cautare 139 | unsigned char inserat = 0; // flag identificare a unei chei deja existente in ABC 140 | root = inserare_nod_ABC(root, card, &inserat); 141 | 142 | if (inserat != 0) 143 | { 144 | printf("Cardul bancar %s NU a fost inserat in ABC\n", card.nr_card); 145 | // dezalocare detinator card 146 | free(card.detinator); 147 | } 148 | else 149 | { 150 | printf("Cardul bancar %s A FOST inserat in ABC\n", card.nr_card); 151 | } 152 | 153 | 154 | fscanf(f, "%[^,],%[^,],%[^,],%f,%[^\n]", card.nr_card, titular, 155 | card.expira_la, &(card.sold), card.moneda); // citire nr card de pe linia urmatoare din fisier 156 | } 157 | fclose(f); 158 | 159 | printf("ABC in traversare in Inordine:\n"); 160 | traversare_Inordine_ABC(root); 161 | 162 | return 0; 163 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1075Sol/Grupa1075Proj/03_Structures.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define CARD_NUMBER_SIZE 16 7 | #define CARD_ARRAY_SIZE 20 8 | 9 | struct Date 10 | { 11 | char month; // stored as value 12 | char year; // stored as value; only last 2 letters are stored 13 | }; 14 | 15 | typedef struct Date Date; 16 | 17 | struct BankCard 18 | { 19 | char* holder; // 4 bytes 20 | char card_no[CARD_NUMBER_SIZE +1]; // 17 bytes 21 | Date exp_date; // 2 bytes -> no alignment (month and year are char) 22 | char* issuer; // 4 bytes -> enforce alignment by adding +1 byte to card_no 23 | float balance; // 4 bytes 24 | }; // 31 bytes; actual length is 32 bytes 25 | 26 | typedef struct BankCard BankCard; 27 | 28 | int main() 29 | { 30 | printf("Size of structure BankCard = %d bytes\n", sizeof(BankCard)); 31 | BankCard v_card[CARD_ARRAY_SIZE], * pv_card; 32 | printf("Size of structure BankCard = %d bytes\n", sizeof(v_card)); 33 | printf("Size of structure BankCard = %d bytes\n", sizeof(pv_card)); 34 | 35 | FILE* f = fopen("CardData.txt", "r"); 36 | 37 | unsigned char count = 0; 38 | unsigned char buffer[200]; 39 | 40 | fgets(buffer, sizeof(buffer), f); 41 | while (!feof(f) && count < CARD_ARRAY_SIZE) 42 | { 43 | char seps[] = ",/\n"; 44 | char* token = strtok(buffer, seps); 45 | v_card[count].holder = malloc(strlen(token) + 1); // +1 for null byte as terminator 46 | strcpy(v_card[count].holder, token); // copy the string token into v_card holder's heap area 47 | 48 | token = strtok(NULL, seps); // get the vard number string 49 | strcpy(v_card[count].card_no, token); 50 | 51 | token = strtok(NULL, seps); // get the month 52 | v_card[count].exp_date.month = atoi(token); // convert string month into integer month 53 | token = strtok(NULL, seps); // get the year 54 | v_card[count].exp_date.year = atoi(token);// convert string year into integer year 55 | 56 | token = strtok(NULL, seps); 57 | v_card[count].issuer = malloc(strlen(token) + 1); 58 | strcpy(v_card[count].issuer, token); 59 | 60 | token = strtok(NULL, seps); // get the balance 61 | v_card[count].balance = (float)atof(token); // convert string balance into float balance 62 | 63 | // increase the counter 64 | count += 1; 65 | // read the next line in the text file CardData.txt 66 | fgets(buffer, sizeof(buffer), f); 67 | } 68 | 69 | fclose(f); 70 | 71 | printf("\n\nCards stored by v_card\n"); 72 | for (unsigned char i = 0; i < count; i++) 73 | { 74 | printf("%s %s\n", v_card[i].holder, v_card[i].card_no); 75 | } 76 | 77 | pv_card = v_card; 78 | printf("\n\nCards stored by v_card accessed by pv_card\n"); 79 | for (unsigned char i = 0; i < count; i++) 80 | { 81 | printf("%s %s\n", pv_card[i].holder, pv_card[i].card_no); 82 | } 83 | 84 | pv_card = malloc(count * sizeof(BankCard)); 85 | for (unsigned char i = 0; i < count; i++) 86 | { 87 | pv_card[i] = v_card[i]; // both arrays share heap mem for holder and issuer; potential issues at deallocation and changing times 88 | // separate heap mem locations for holder and issuer 89 | pv_card[i].holder = malloc(strlen(v_card[i].holder) + 1); 90 | strcpy(pv_card[i].holder, v_card[i].holder); 91 | pv_card[i].issuer = malloc(strlen(v_card[i].issuer) + 1); 92 | strcpy(pv_card[i].issuer, v_card[i].issuer); 93 | } 94 | 95 | printf("\n\nCards stored in heap memory and accessed by pv_card\n"); 96 | for (unsigned char i = 0; i < count; i++) 97 | { 98 | printf("%s %s\n", pv_card[i].holder, pv_card[i].card_no); 99 | } 100 | 101 | v_card[0].holder[0] = 'X'; 102 | printf("\n\nCards stored by v_card after changing the v_card first item\n"); 103 | for (unsigned char i = 0; i < count; i++) 104 | { 105 | printf("%s %s\n", v_card[i].holder, v_card[i].card_no); 106 | } 107 | printf("\n\nCards stored in heap memory after changing the v_card first item\n"); 108 | for (unsigned char i = 0; i < count; i++) 109 | { 110 | printf("%s %s\n", pv_card[i].holder, pv_card[i].card_no); 111 | } 112 | 113 | // deallocation of v_card extensions to heap mem 114 | for (unsigned char i = 0; i < count; i++) 115 | { 116 | free(v_card[i].holder); 117 | free(v_card[i].issuer); 118 | } 119 | 120 | // deallocation of pv_card 121 | // step 1: deallocte holder and issuer for each item in pv_card 122 | for (unsigned char i = 0; i < count; i++) 123 | { 124 | free(pv_card[i].holder); 125 | free(pv_card[i].issuer); 126 | } 127 | // step 2: dealocate the array itself 128 | free(pv_card); 129 | 130 | 131 | 132 | return 0; 133 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1075Sol/Grupa1075Proj/06_DoubleLists.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define CARD_NUMBER_SIZE 16 7 | #define CARD_ARRAY_SIZE 20 8 | 9 | struct Date 10 | { 11 | char month; // stored as value 12 | char year; // stored as value; only last 2 letters are stored 13 | }; 14 | 15 | typedef struct Date Date; 16 | 17 | struct BankCard 18 | { 19 | char* holder; 20 | char card_no[CARD_NUMBER_SIZE + 1]; 21 | Date exp_date; 22 | char* issuer; 23 | float balance; 24 | }; 25 | 26 | typedef struct BankCard BankCard; 27 | 28 | struct NodeD 29 | { 30 | BankCard data; 31 | struct NodeD* next, *prev; 32 | }; 33 | 34 | typedef struct NodeD NodeD; 35 | 36 | struct DoubleList 37 | { 38 | NodeD* head, * tail; 39 | }; // structure to handle the both endpoints of the double list: head and tail 40 | 41 | typedef struct DoubleList DoubleList; 42 | 43 | DoubleList insert_card_double_list(DoubleList list, BankCard data) 44 | { 45 | NodeD* new_node = malloc(sizeof(NodeD)); 46 | new_node->data = data; 47 | new_node->next = NULL; 48 | new_node->prev = list.tail; // current tail of the double list; can be NULL when double list is empty 49 | 50 | if (list.tail == NULL) 51 | { 52 | // the double is empty 53 | list.head = new_node; 54 | list.tail = new_node; // new_node becomes the first, the last and the uniques node in my double list 55 | } 56 | else 57 | { 58 | // there is one node at least in my double list 59 | list.tail->next = new_node; // add new_node to the end of the list 60 | list.tail = new_node; // update the tail of the double list to the new_node added to the list 61 | } 62 | 63 | return list; 64 | } 65 | 66 | void parse_double_list(DoubleList list) 67 | { 68 | printf("Double list head-to-tail:\n"); 69 | NodeD* temp = list.head; 70 | while (temp != NULL) 71 | { 72 | printf("%s %s\n", temp->data.holder, temp->data.card_no); 73 | temp = temp->next; 74 | } 75 | 76 | printf("\nDouble list tail-to-head:\n"); 77 | temp = list.tail; 78 | while (temp != NULL) 79 | { 80 | printf("%s %s\n", temp->data.holder, temp->data.card_no); 81 | temp = temp->prev; 82 | } 83 | } 84 | 85 | DoubleList delete_head_double_list(DoubleList list) 86 | { 87 | 88 | if (list.head != NULL) 89 | { 90 | // there is one node at least in double list 91 | NodeD* temp = list.head; 92 | list.head = list.head->next; // update the head of the list to the second node in the list 93 | 94 | if (list.head == NULL) 95 | { 96 | // double list becomes empty after delettion 97 | list.tail = NULL; 98 | } 99 | else 100 | { 101 | list.head->prev = NULL; 102 | } 103 | 104 | free(temp->data.holder); // deallocate string for holder 105 | free(temp->data.issuer); // deallocate string fo issuer 106 | free(temp); // deallocate the node iteself 107 | } 108 | 109 | return list; 110 | } 111 | 112 | // swap two nodes in a double list 113 | 114 | // deallocate the double list 115 | 116 | int main() 117 | { 118 | FILE* f = fopen("CardData.txt", "r"); 119 | 120 | unsigned char buffer[200]; 121 | DoubleList double_list; // local variable to store the head and tail of one single double list data structure 122 | 123 | double_list.head = NULL; // head does not exist for an empty double list 124 | double_list.tail = NULL; // tail does not exist for an empty double list 125 | 126 | fgets(buffer, sizeof(buffer), f); 127 | while (!feof(f)) 128 | { 129 | BankCard card; 130 | char seps[] = ",/\n"; 131 | char* token = strtok(buffer, seps); 132 | card.holder = malloc(strlen(token) + 1); // +1 for null byte as terminator 133 | strcpy(card.holder, token); // copy the string token into v_card holder's heap area 134 | 135 | token = strtok(NULL, seps); // get the vard number string 136 | strcpy(card.card_no, token); 137 | 138 | token = strtok(NULL, seps); // get the month 139 | card.exp_date.month = atoi(token); // convert string month into integer month 140 | token = strtok(NULL, seps); // get the year 141 | card.exp_date.year = atoi(token); // convert string year into integer year 142 | 143 | token = strtok(NULL, seps); 144 | card.issuer = malloc(strlen(token) + 1); 145 | strcpy(card.issuer, token); 146 | 147 | token = strtok(NULL, seps); // get the balance 148 | card.balance = (float)atof(token); // convert string balance into float balance 149 | 150 | // insert card data into a double list 151 | double_list = insert_card_double_list(double_list, card); 152 | 153 | // read the next line in the text file CardData.txt 154 | fgets(buffer, sizeof(buffer), f); 155 | } 156 | 157 | fclose(f); 158 | 159 | 160 | printf("Data content of double list:\n"); 161 | parse_double_list(double_list); 162 | 163 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/05_ListeDuble.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define CARD_NO_LENGTH 16 6 | #define MONEDA_COD_LENGTH 3 7 | 8 | struct CardBancar 9 | { 10 | char nr_card[CARD_NO_LENGTH + 1]; 11 | char* detinator; 12 | char expira_la[6]; 13 | float sold; 14 | char moneda[MONEDA_COD_LENGTH + 1]; 15 | }; 16 | 17 | typedef struct CardBancar CardBancar; 18 | 19 | struct NodD 20 | { 21 | CardBancar card; 22 | struct NodD* next, *prev; 23 | }; 24 | typedef struct NodD NodD; 25 | 26 | 27 | struct ListaDubla 28 | { 29 | NodD* prim, * ultim; // adrese catre primul, respectiv ultimul nod din lista dubla 30 | }; 31 | 32 | typedef struct ListaDubla ListaDubla; 33 | 34 | // functie de inserare nod la inceputul listei duble 35 | ListaDubla inserare_inceput(ListaDubla lista, CardBancar data) 36 | { 37 | NodD* nou = malloc(sizeof(NodD)); 38 | nou->card = data; // salvare date din card bancar 39 | nou->prev = NULL; // predecesor obligatoriu NULL 40 | nou->next = lista.prim; // succesor obligatoriu actual inceput de lista dubla 41 | 42 | if (lista.prim == NULL) 43 | { 44 | // nu exista noduri in lista dubla 45 | lista.ultim = nou; 46 | } 47 | else 48 | { 49 | // exista cel putin un nod in lista dubla 50 | // se actualizeaza actual predecesor pentru primul nod din lista dubla 51 | lista.prim->prev = nou; 52 | } 53 | lista.prim = nou; 54 | 55 | return lista; 56 | } 57 | 58 | // functie de traversare lista dubla 59 | void traversare_listadubla(ListaDubla lista) 60 | { 61 | NodD* temp = lista.prim; 62 | printf("\nTraversare prim->ultim:\n"); 63 | while (temp != NULL) 64 | { 65 | printf("%s %s\n", temp->card.nr_card, temp->card.detinator); 66 | temp = temp->next; 67 | } 68 | 69 | temp = lista.ultim; 70 | printf("\n\nTraversare ultim->prim:\n"); 71 | while (temp != NULL) 72 | { 73 | printf("%s %s\n", temp->card.nr_card, temp->card.detinator); 74 | temp = temp->prev; 75 | } 76 | } 77 | 78 | // functie de stergere nod la sfarsitul listei duble 79 | ListaDubla stergere_sfarsit(ListaDubla lista) 80 | { 81 | if (lista.prim != NULL) 82 | { 83 | // exista cel putin 1 nod in lista dubla 84 | if (lista.prim == lista.ultim) 85 | { 86 | // exista 1 singur nod in lista dubla 87 | free(lista.prim->card.detinator); 88 | free(lista.prim); 89 | 90 | lista.prim = NULL; 91 | lista.ultim = NULL; // lista devine empty 92 | } 93 | else 94 | { 95 | NodD* temp = lista.ultim; 96 | lista.ultim = lista.ultim->prev; // nodul din fata lui temp devine ultimul din lista dubla 97 | lista.ultim->next = NULL; 98 | 99 | free(temp->card.detinator); 100 | free(temp); 101 | } 102 | } 103 | 104 | return lista; 105 | } 106 | 107 | // functie de stergere a nodurilor cu acelasi detinator de card bancar 108 | 109 | // functie de sortare a nodurilor din lista dubla (sold card bancar) 110 | 111 | // functie de intreschimbare doua noduri adiacente in lista dubla 112 | 113 | // functie care salveaza carduri bancare (acelasi detinator) intr-o lista simpla 114 | 115 | int main() 116 | { 117 | FILE* f; // pointer la structura FILE (handler de fisier) 118 | ListaDubla listaD; // variabila de acces la capetele unei liste duble 119 | listaD.prim = NULL; 120 | listaD.ultim = NULL; 121 | 122 | f = fopen("CarduriBancare.txt", "r"); 123 | 124 | char titular[150]; 125 | CardBancar card; 126 | fscanf(f, "%[^,],%[^,],%[^,],%f,%[^\n]", card.nr_card, titular, 127 | card.expira_la, &(card.sold), card.moneda); 128 | while (!feof(f)) // conditie aplicata dupa o incercare de a citi nr card bancar 129 | { 130 | card.detinator = malloc(strlen(titular) + 1); // +1 pt terminatorul de string (byte 0x00) 131 | strcpy(card.detinator, titular); // copiere string nume detinator in variabila temporara card 132 | 133 | fscanf(f, "\n"); 134 | 135 | // inserare in lista simpla card bancar "pregatit" in variabila temporara card 136 | listaD = inserare_inceput(listaD, card); 137 | 138 | fscanf(f, "%[^,],%[^,],%[^,],%f,%[^\n]", card.nr_card, titular, 139 | card.expira_la, &(card.sold), card.moneda); // citire date card de pe linia urmatoare 140 | } 141 | fclose(f); 142 | printf("Lista dubla dupa creare:\n"); 143 | traversare_listadubla(listaD); 144 | 145 | // apel functie care creeaza lista simpla carduri cu acelasi detinator 146 | 147 | // stergere nod la sfarsitul listei duble 148 | listaD = stergere_sfarsit(listaD); 149 | 150 | printf("\n\nLista dubla dupa stergerea ultimului nod:\n"); 151 | traversare_listadubla(listaD); 152 | 153 | // dezalocare structura lista dubla 154 | while (listaD.prim != NULL) 155 | { 156 | listaD = stergere_sfarsit(listaD); 157 | } 158 | 159 | printf("\n\nLista dubla dupa dezalocarea:\n"); 160 | traversare_listadubla(listaD); 161 | 162 | return 0; 163 | } 164 | -------------------------------------------------------------------------------- /2024-2025/Grupa1076Sol/Grupa1076Proj/04_SimpleList.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define CARD_NUMBER_LENGTH 16 8 | #define EXPIRING_DATE_FORMAT_LENGTH 5 // MM/YY 9 | 10 | struct BankCard 11 | { 12 | char* holder; 13 | char card_no[CARD_NUMBER_LENGTH + 1]; 14 | float balance; 15 | char exp_date[EXPIRING_DATE_FORMAT_LENGTH + 1]; 16 | char* currency; 17 | }; 18 | 19 | typedef struct BankCard BankCard; 20 | 21 | struct Node 22 | { 23 | BankCard data; 24 | struct Node* next; // mem address of the next item (node) in the chain 25 | }; 26 | 27 | typedef struct Node Node; 28 | 29 | // insert a node into a simple list 30 | Node* insert_node(Node* list, BankCard bc) 31 | { 32 | Node* t = list; 33 | 34 | if (t) 35 | { 36 | // list contains one node at least 37 | while (t->next != NULL) 38 | t = t->next; 39 | } 40 | 41 | Node* new_node = malloc(sizeof(Node)); 42 | new_node->data = bc; 43 | new_node->next = NULL; // mandatory NULL because the new node will be the last node after insert 44 | 45 | if (t != NULL) 46 | { 47 | // there is one single node at least 48 | // t is the last node in the list 49 | t->next = new_node; // new node become the new last node 50 | return list; 51 | } 52 | else 53 | { 54 | return new_node; // new node is the first and unique node within the list 55 | } 56 | } 57 | 58 | void parse_list(Node* list) 59 | { 60 | Node* temp = list; 61 | while (temp != NULL) 62 | { 63 | printf("%s %s\n", temp->data.holder, temp->data.card_no); 64 | 65 | temp = temp->next; // update temp with the next node in the chain 66 | } 67 | } 68 | 69 | Node* delete_node_middle(Node* list, char* card_number) 70 | { 71 | if (list != NULL) 72 | { 73 | // the list is not empty 74 | if (strcmp(list->data.card_no, card_number) == 0) 75 | { 76 | // the node to be deleted is the head of the list 77 | Node* temp = list; 78 | list = list->next; 79 | 80 | free(temp->data.holder); // deallocate holder string 81 | free(temp->data.currency); // deallocate currency string 82 | free(temp); // deallocate the node itself 83 | } 84 | else 85 | { 86 | // the node to be deleted is not in the head of the list 87 | Node* temp = list; 88 | Node* temp_del = list->next; 89 | while (temp_del != NULL) 90 | { 91 | if (strcmp(temp_del->data.card_no, card_number) == 0) 92 | { 93 | temp->next = temp_del->next; // temp is the node just before the temp_del 94 | // the new next node node for temp will be the actual next node for temp_del 95 | 96 | free(temp_del->data.holder); 97 | free(temp_del->data.currency); 98 | free(temp_del); 99 | temp_del = NULL; 100 | } 101 | else 102 | { 103 | temp = temp_del; 104 | temp_del = temp_del->next; 105 | } 106 | } 107 | } 108 | } 109 | 110 | return list; 111 | } 112 | 113 | 114 | int main() 115 | { 116 | FILE* f = fopen("CardData.txt", "r"); 117 | 118 | Node* head = NULL; 119 | 120 | unsigned char buffer[200]; 121 | while (fgets(buffer, sizeof(buffer), f)) 122 | { 123 | BankCard card; 124 | char seps[] = ",\n"; 125 | char* token = strtok(buffer, seps); // splitting started from the beginning of buffer array 126 | strcpy(card.card_no, token); 127 | 128 | token = strtok(NULL, seps); // continue the splitting of buffer from the current point 129 | strcpy(card.exp_date, token); 130 | 131 | token = strtok(NULL, seps); // continue the splitting of buffer from the current point 132 | card.holder = malloc(strlen(token) + 1); 133 | strcpy(card.holder, token); 134 | 135 | token = strtok(NULL, seps); // continue the splitting of buffer from the current point 136 | card.currency = malloc(strlen(token) + 1); 137 | strcpy(card.currency, token); 138 | 139 | token = strtok(NULL, seps); // continue the splitting of buffer from the current point 140 | card.balance = (float)atof(token); 141 | 142 | // insert card data into a simple list 143 | head = insert_node(head, card); 144 | } 145 | 146 | fclose(f); 147 | 148 | printf("Simple list after creation:\n"); 149 | parse_list(head); 150 | 151 | head = delete_node_middle(head, "6542777788881908"); 152 | printf("\nSimple list after deletion of one node:\n"); 153 | parse_list(head); 154 | 155 | // deallocate the entire list by calling the one single node deletion 156 | // for the card number taken from the head everytime 157 | while (head != NULL) 158 | { 159 | head = delete_node_middle(head, head->data.card_no); 160 | } 161 | printf("\nSimple list after deallocation:\n"); 162 | parse_list(head); 163 | 164 | 165 | // insert a node in the middle of the list (define criteria!) 166 | // delete a node at the begining and the end of the list 167 | 168 | return 0; 169 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/05_ListeDuble.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define DIM_NR_CARD 16 9 | #define DIM_DATA_EXPIRARE 5 10 | 11 | struct CardBancar 12 | { 13 | char* titular; // 4 bytes 14 | char nr_card[DIM_NR_CARD + 1]; // +1 pt byte terminator de string; 20 bytes (17 + 3 padding) 15 | float sold; // 4 bytes 16 | char* emitent; // 4 bytes 17 | char data_expirare[DIM_DATA_EXPIRARE + 1]; // LL/AA; 8 bytes (6 + 2 padding) 18 | }; 19 | 20 | typedef struct CardBancar CardBancar; 21 | 22 | struct NodD 23 | { 24 | CardBancar cb; 25 | struct NodD* next, *prev; 26 | }; 27 | 28 | typedef struct NodD NodD; 29 | 30 | struct ListaDubla 31 | { 32 | NodD* prim, * ultim; 33 | }; 34 | 35 | typedef struct ListaDubla ListaDubla; 36 | 37 | ListaDubla inserare_nod_sfarsit(ListaDubla lista, CardBancar data) 38 | { 39 | NodD* nou = malloc(sizeof(NodD)); 40 | nou->cb = data; 41 | nou->next = NULL; // nou va deveni ultimul nod din lista (nu va avea succesor) 42 | nou->prev = lista.ultim; 43 | 44 | if (lista.prim == NULL) 45 | { 46 | // lista este empty 47 | lista.prim = nou; 48 | } 49 | else 50 | { 51 | // lista contine cel putin 1 nod 52 | lista.ultim->next = nou; // atasarea lui nou la lista 53 | } 54 | lista.ultim = nou; 55 | 56 | return lista; 57 | } 58 | 59 | void traversare_listadubla(ListaDubla lista) 60 | { 61 | // traversare lista dubla in ambele sensuri 62 | NodD* temp = lista.prim; 63 | printf("Lista dubla traversare prim->ultim\n"); 64 | while (temp) 65 | { 66 | printf("%s %s\n", temp->cb.nr_card, temp->cb.titular); 67 | temp = temp->next; 68 | } 69 | 70 | temp = lista.ultim; 71 | printf("Lista dubla traversare ultim->prim\n"); 72 | while (temp) 73 | { 74 | printf("%s %s\n", temp->cb.nr_card, temp->cb.titular); 75 | temp = temp->prev; 76 | } 77 | } 78 | 79 | ListaDubla stergere_inceput(ListaDubla lista) 80 | { 81 | if (lista.prim != NULL) 82 | { 83 | NodD* temp = lista.prim; 84 | lista.prim = lista.prim->next; 85 | if (lista.prim == NULL) 86 | { 87 | //lista devine empty 88 | lista.ultim = NULL; 89 | } 90 | else 91 | { 92 | // lista contine cel putin 2 noduri inainte de stergere 93 | lista.prim->prev = NULL; 94 | } 95 | 96 | free(temp->cb.emitent); // dezalocare string emitent (extensie din card bancar) 97 | free(temp->cb.titular); // dezalocare string titular (extensie din card bancar) 98 | free(temp); // dezalocare nod temp (NodD*) 99 | } 100 | 101 | return lista; 102 | } 103 | 104 | 105 | // functie interschimb noduri adiacente in lista dubla 106 | // cu modificarea adreselor de legatura 107 | 108 | int main() 109 | { 110 | FILE* f = NULL; 111 | f = fopen("CarduriBancare.txt", "r"); 112 | 113 | CardBancar card; 114 | ListaDubla listaD; 115 | listaD.prim = NULL; // lista nu contine un prim nod 116 | listaD.ultim = NULL; // lista nu contine un ultim nod 117 | 118 | char temp_buff[100]; // buffer temporar pentru stocare linii preluate din fisier text 119 | fgets(temp_buff, sizeof(temp_buff), f); 120 | 121 | while (!feof(f)) 122 | { 123 | strtok(temp_buff, "\n"); 124 | card.titular = malloc(strlen(temp_buff) + 1); 125 | strcpy(card.titular, temp_buff); 126 | 127 | fgets(temp_buff, sizeof(temp_buff), f); 128 | strtok(temp_buff, "\n"); 129 | strcpy(card.nr_card, temp_buff); 130 | 131 | fgets(temp_buff, sizeof(temp_buff), f); 132 | strtok(temp_buff, "\n"); 133 | card.sold = (float)atof(temp_buff); // conversie ASCII-to-Binary pentru float 134 | 135 | fgets(temp_buff, sizeof(temp_buff), f); 136 | strtok(temp_buff, "\n"); 137 | card.emitent = malloc(strlen(temp_buff) + 1); 138 | strcpy(card.emitent, temp_buff); 139 | 140 | fgets(temp_buff, sizeof(temp_buff), f); 141 | strtok(temp_buff, "\n"); 142 | strcpy(card.data_expirare, temp_buff); 143 | 144 | // inserare date card in lista simpla 145 | listaD = inserare_nod_sfarsit(listaD, card); 146 | 147 | // incercare preluare titular card urmator 148 | fgets(temp_buff, sizeof(temp_buff), f); 149 | } 150 | fclose(f); 151 | 152 | printf("Lista dubla dupa creare:\n"); 153 | traversare_listadubla(listaD); 154 | 155 | // stergere nod la inceput 156 | listaD = stergere_inceput(listaD); 157 | printf("\n\nLista dubla dupa stergere nod la inceput:\n"); 158 | traversare_listadubla(listaD); 159 | 160 | // dezalocare lista dubla 161 | while (listaD.prim != NULL) 162 | { 163 | // exista cel putin un nod in lista dubla 164 | // care poate fi sters/eliminat din lista 165 | listaD = stergere_inceput(listaD); 166 | } 167 | 168 | printf("\n\nLista dubla dupa dezalocare:\n"); 169 | traversare_listadubla(listaD); 170 | 171 | // stergere la interior (titular card bancar) 172 | 173 | // algoritmul QuickSort 174 | 175 | 176 | return 0; 177 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Proj/04_ListeSimple.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define DIM_CARD_BANCAR 16 9 | #define DIM_DATA_EXPIRARE 7 10 | #define DIM_MONEDA 3 11 | 12 | 13 | struct CardBancar 14 | { 15 | char nr_card[DIM_CARD_BANCAR + 1]; // +1 pentru terminator string; 20 bytes (17 + 3 padding) 16 | char* titular; // 4 bytes 17 | char data_expirare[DIM_DATA_EXPIRARE + 1]; // +1 pentru terminator string; 12 bytes (9 + 3 padding) 18 | float sold; // 4 bytes 19 | char moneda[DIM_MONEDA + 1]; // cod moneda; 4 bytes (no padding) 20 | }; 21 | 22 | typedef struct CardBancar CardBancar; 23 | 24 | struct Nod 25 | { 26 | CardBancar cb; 27 | struct Nod* next; 28 | }; 29 | 30 | typedef struct Nod Nod; 31 | 32 | // inserare nod la interior pe criteriu definit (dupa nod cu nr_card specificat) 33 | Nod* inserare_nod_interior(Nod* lista, CardBancar data, char* numar_card) 34 | { 35 | if (lista == NULL) 36 | { 37 | // lista este empty (0 noduri) 38 | Nod* nou = malloc(sizeof(Nod)); 39 | nou->cb = data; // partajare temporara mem heap pt titular 40 | nou->next = NULL; 41 | lista = nou; 42 | } 43 | else 44 | { 45 | // lista contine cel putin 1 nod 46 | Nod* temp = lista; 47 | while (temp != NULL) 48 | { 49 | if (strcmp(temp->cb.nr_card, numar_card) == 0) 50 | { 51 | // nodul temp este identificat ca predecesor al lui nou 52 | Nod* nou = malloc(sizeof(Nod)); 53 | nou->cb = data; // partajare temporara mem heap pt titular 54 | nou->next = temp->next; 55 | temp->next = nou; 56 | temp = NULL; // pentru a forta iesirea din while 57 | // nodurile ramase de parsat nu intereseaza la inserare 58 | } 59 | else 60 | temp = temp->next; 61 | } 62 | } 63 | 64 | return lista; 65 | } 66 | 67 | void traversare_listasimpla(Nod* lista) 68 | { 69 | Nod* temp = lista; 70 | while (temp != NULL) 71 | { 72 | printf("%s %s\n", temp->cb.nr_card, temp->cb.titular); 73 | 74 | temp = temp->next; 75 | } 76 | } 77 | 78 | Nod* stergere_inceput(Nod* lista) 79 | { 80 | if (lista != NULL) 81 | { 82 | // exista cel putin 1 nod in lista simpla 83 | Nod* temp = lista; 84 | lista = lista->next; 85 | 86 | free(temp->cb.titular); // dezalocare string pentru titular card bancar 87 | free(temp); // dezalocare nod de lista simpla 88 | } 89 | 90 | return lista; 91 | } 92 | 93 | int main() 94 | { 95 | // preluare date din fisiere pentru carduri bancare 96 | FILE* f = NULL; 97 | f = fopen("CarduriBancare.txt", "r"); 98 | 99 | CardBancar card; 100 | Nod* prim = NULL; 101 | 102 | char buffer[150]; 103 | char sep[] = ";\n"; 104 | 105 | fgets(buffer, sizeof(buffer), f); 106 | 107 | while (!feof(f)) 108 | { 109 | char* token = NULL; 110 | token = strtok(buffer, sep); 111 | strcpy(card.nr_card, token); 112 | 113 | token = strtok(NULL, sep); 114 | card.titular = malloc(strlen(token) + 1); 115 | strcpy(card.titular, token); 116 | 117 | token = strtok(NULL, sep); 118 | strcpy(card.data_expirare, token); 119 | 120 | token = strtok(NULL, sep); 121 | card.sold = (float)atof(token); 122 | 123 | token = strtok(NULL, sep); 124 | strcpy(card.moneda, token); 125 | 126 | // apel de functie pentru inserare nod in lista simpla 127 | if (prim == NULL) 128 | { 129 | // lista este empty 130 | prim = inserare_nod_interior(prim, card, ""); 131 | } 132 | else 133 | { 134 | prim = inserare_nod_interior(prim, card, prim->cb.nr_card); 135 | } 136 | 137 | // verificare prezenta card in lista simpla 138 | Nod* temp = prim; 139 | unsigned char flag = 0; // card.nr_card nu este prezent in lista simpla 140 | while ((temp != NULL) && (flag == 0)) 141 | { // cautare prezenta card.nr_card in lista simpla dupa apel functie inserare nod 142 | if (strcmp(temp->cb.nr_card, card.nr_card) == 0) 143 | { 144 | flag = 1; // card.nr_card este gasit in lista simpla 145 | } 146 | temp = temp->next; 147 | } 148 | if (flag == 0) // card nu a fost inserat in lista simpla 149 | { 150 | // card.nr_card nu a fost gasit in lista simple, deci nu a avut loc inserarea 151 | free(card.titular); 152 | } 153 | 154 | // incercare preluare linie urmatoare (daca exista) 155 | fgets(buffer, sizeof(buffer), f); 156 | } 157 | fclose(f); 158 | 159 | printf("Lista simpla dupa creare:\n"); 160 | traversare_listasimpla(prim); 161 | 162 | prim = stergere_inceput(prim); 163 | printf("\n\nLista simpla dupa stergerea primului nod:\n"); 164 | traversare_listasimpla(prim); 165 | 166 | while (prim != NULL) 167 | { 168 | // exista cel putin 1 nod in lista simpla 169 | prim = stergere_inceput(prim); 170 | } 171 | printf("\n\nLista simpla dupa dezalocare:\n"); 172 | traversare_listasimpla(prim); 173 | 174 | // stergere nod din lista simpla (inceput, sfarsit) 175 | } -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/12_Arbori.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct NodTree { 5 | int key; 6 | struct NodTree* fiu, * frate; 7 | }; 8 | 9 | // r - radacina subarbore; nod curent in abordare recursiva 10 | // id - cheie nod parinte care se cauta pentru nodul de inserat 11 | // gasit - adresa nodului cu id identificat in arbore; pointer trimis prin adresa 12 | void cautaNod(struct NodTree* r, int id, struct NodTree** gasit) { 13 | if (r) { 14 | printf("Nod curent este: %d\n", r->key); 15 | if (r->key == id) { // prelucrez nodul curent r 16 | *gasit = r; 17 | return; 18 | } 19 | cautaNod(r->fiu, id, gasit); // parsez primul subarbore descendent lui r 20 | if (*gasit) 21 | return; 22 | if (r->fiu) { 23 | struct NodTree* tmp = r->fiu; 24 | while (tmp->frate) { // parsez restul de subarbori descendenti lui r 25 | cautaNod(tmp->frate, id, gasit); 26 | if (*gasit) 27 | return; 28 | tmp = tmp->frate; 29 | } 30 | } 31 | } 32 | } 33 | 34 | 35 | void preordine(struct NodTree* r) { 36 | if (r) { 37 | printf("%d ", r->key); 38 | 39 | preordine(r->fiu); // parsez primul subarbore descendent lui r 40 | 41 | if (r->fiu) { 42 | struct NodTree* tmp = r->fiu; 43 | while (tmp->frate) { // parsez restul de subarbori descendenti lui r 44 | preordine(tmp->frate); 45 | tmp = tmp->frate; 46 | } 47 | } 48 | } 49 | } 50 | 51 | // r - nod curent (radacina subarbore) 52 | // cheie - cheia nodului de inserat 53 | // idParinte - cheie nod parinte sub care se aseaza nodul nou cheie 54 | struct NodTree* inserare(struct NodTree* r, int cheie, int idParinte) { 55 | 56 | if (!idParinte) { // nodul nou (cu cheie) va deveni noua radacina de arbore 57 | struct NodTree* nou = (struct NodTree*)malloc(sizeof(struct NodTree)); // nodul care se insereaza devine nod radacina 58 | nou->key = cheie; 59 | nou->fiu = NULL; 60 | nou->frate = NULL; 61 | 62 | if (r) { // exista cel putin 1 nod in arbore (radacina arbore curent) 63 | nou->fiu = r; // arborele devine sub-arbore pentru noua radacina nou 64 | } 65 | 66 | r = nou; 67 | } 68 | else { // se cauta nodul cu idParinte care va primi descendent pe nou cu cheie 69 | struct NodTree* nou = (struct NodTree*)malloc(sizeof(struct NodTree)); 70 | nou->key = cheie; 71 | nou->fiu = NULL; 72 | nou->frate = NULL; 73 | 74 | struct NodTree* p = NULL; 75 | cautaNod(r, idParinte, &p); 76 | if (p && !p->fiu) 77 | p->fiu = nou; // nodul nou devine prim fiu al parintelui idParinte 78 | else { 79 | if (p) 80 | { // nodul nou devine ultimul frate al primului fiu pentru parintele idParinte 81 | if (!p->fiu->frate) 82 | p->fiu->frate = nou; // nou este primul frate pentru p->fiu (p parinte cu idParinte) 83 | else { 84 | struct NodTree* tmp = p->fiu; 85 | while (tmp->frate) 86 | tmp = tmp->frate; 87 | 88 | tmp->frate = nou; // nodul nou se insereaza la sfarsitul listei de frati pentru p->fiu 89 | } 90 | } 91 | } 92 | } 93 | 94 | return r; 95 | } 96 | 97 | 98 | struct NodTree* dezalocare_arbore(struct NodTree* r) { 99 | if (r) { 100 | struct NodTree* p_frate = NULL; 101 | if (r->fiu) 102 | { 103 | p_frate = r->fiu->frate; 104 | } 105 | r->fiu = dezalocare_arbore(r->fiu); // parsez primul subarbore descendent lui r 106 | 107 | if (p_frate) { 108 | struct NodTree* tmp = p_frate; 109 | while (tmp) { // parsez restul de subarbori descendenti lui r 110 | p_frate = tmp->frate; 111 | tmp = dezalocare_arbore(tmp); 112 | tmp = p_frate; 113 | } 114 | } 115 | 116 | // prelucrare nod - dezalocare structura dinamica din mem heap 117 | printf("Dezalocare nod %d\n", r->key); 118 | free(r); 119 | r = NULL; 120 | } 121 | 122 | return r; 123 | } 124 | 125 | void main() { 126 | struct NodTree* root = NULL; 127 | 128 | // inserare cheie in arbore 129 | printf("\nInserare cheie 1\n"); 130 | root = inserare(root, 1, 0); 131 | printf("\nInserare cheie 2\n"); 132 | root = inserare(root, 2, 1); 133 | printf("\nInserare cheie 3\n"); 134 | root = inserare(root, 3, 1); 135 | printf("\nInserare cheie 4\n"); 136 | root = inserare(root, 4, 1); 137 | printf("\nInserare cheie 5\n"); 138 | root = inserare(root, 5, 2); 139 | printf("\nInserare cheie 6\n"); 140 | root = inserare(root, 6, 2); 141 | printf("\nInserare cheie 7\n"); 142 | root = inserare(root, 7, 6); 143 | printf("\nInserare cheie 8\n"); 144 | root = inserare(root, 8, 7); 145 | 146 | printf("\nArborele in traversare in preordine:\n\n"); 147 | preordine(root); 148 | printf("\n\n"); 149 | 150 | printf("\nInserare cheie 9\n"); 151 | root = inserare(root, 9, 7); 152 | printf("\nArborele in traversare in preordine:\n\n"); 153 | preordine(root); 154 | printf("\n\n"); 155 | 156 | // dezalocare arbore oarecare implementat fiu-frate cu structuri dinamice 157 | root = dezalocare_arbore(root); 158 | printf("\nArborele in traversare in preordine DUPA DEZALOCARE:\n\n"); 159 | preordine(root); 160 | printf("\n\n"); 161 | } -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/13_AVL.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define LINESIZE 128 8 | 9 | struct Student { 10 | int id; 11 | char* nume; 12 | float medie; 13 | }; 14 | 15 | struct NodAVL { 16 | struct Student stud; 17 | char GE; 18 | struct NodAVL* st, * dr; 19 | }; 20 | 21 | typedef struct Student Student; 22 | typedef struct NodAVL NodAVL; 23 | 24 | 25 | // maximul a doi intregi 26 | int maxim(int a, int b) { 27 | return a > b ? a : b; 28 | } 29 | 30 | 31 | // inaltime (sub)arbore r 32 | int h(NodAVL* r) { 33 | if (r) 34 | return 1 + maxim(h(r->st), h(r->dr)); 35 | else 36 | return 0; 37 | } 38 | 39 | 40 | // gradul de echilibru al unui nod 41 | void calculGENod(NodAVL* r) { 42 | if (r) { 43 | //prelucrare (calcul GE) 44 | r->GE = h(r->dr) - h(r->st); 45 | } 46 | } 47 | 48 | 49 | // rotire simpla la dreapta 50 | NodAVL* rotireSimplaDr(NodAVL* pivot, NodAVL* fiuSt) { 51 | pivot->st = fiuSt->dr; // stanga pivotului devine subarbore Y (vezi curs) 52 | calculGENod(pivot); // recalculare GE pivot 53 | fiuSt->dr = pivot; // fiul pivotului promoveaza (dreapta devine pivot) pe nivel superior 54 | calculGENod(fiuSt); // recalculare GE fiu al pivotului 55 | 56 | return fiuSt; 57 | } 58 | 59 | // rotire simpla la stanga 60 | NodAVL* rotireSimplaSt(NodAVL* pivot, NodAVL* fiuDr) { 61 | pivot->dr = fiuDr->st; // dreapta pivot devine subarbore Y 62 | calculGENod(pivot); 63 | fiuDr->st = pivot; // fiul pivotului promoveaza (stanga sa devine pivot) pe nivel superior 64 | calculGENod(fiuDr); 65 | 66 | return fiuDr; 67 | } 68 | 69 | // rotire dubla stanga-dreapta 70 | NodAVL* rotireDblStDr(NodAVL* pivot, NodAVL* fiuSt) { 71 | //aducerea dezechilibrului pe aceeasi directie 72 | pivot->st = rotireSimplaSt(fiuSt, fiuSt->dr); // rotire de pregatire (efectuata in fiu stanga al pivotului care devine pivot la rotirea #1) 73 | calculGENod(pivot); 74 | fiuSt = pivot->st; // actualizare fiu stanga al pivotului 75 | //rotire propriu-zisa in pivot 76 | fiuSt = rotireSimplaDr(pivot, fiuSt); // dezechilibrul este pe aceeasi directie 77 | calculGENod(fiuSt); 78 | 79 | return fiuSt; 80 | } 81 | 82 | // rotire dubla dreapta-stanga 83 | NodAVL* rotireDblDrSt(NodAVL* pivot, NodAVL* fiuDr) { 84 | // aducerea dezechilibrului pe aceeasi directie 85 | pivot->dr = rotireSimplaDr(fiuDr, fiuDr->st); 86 | calculGENod(pivot); 87 | fiuDr = pivot->dr; 88 | // rotire propriu-zisa in pivot 89 | fiuDr = rotireSimplaSt(pivot, fiuDr); 90 | calculGENod(fiuDr); 91 | 92 | return fiuDr; 93 | } 94 | 95 | // inserare nod in AVL 96 | NodAVL* insNodAVL(NodAVL* r, Student s, int* err) { 97 | if (r) { 98 | if (r->stud.id > s.id) 99 | r->st = insNodAVL(r->st, s, err); 100 | else 101 | if (r->stud.id < s.id) 102 | r->dr = insNodAVL(r->dr, s, err); 103 | else 104 | *err = 1; 105 | } 106 | else { 107 | NodAVL* nou; 108 | nou = (NodAVL*)malloc(sizeof(NodAVL)); 109 | nou->stud = s; 110 | nou->st = NULL; 111 | nou->dr = NULL; 112 | r = nou; 113 | } 114 | 115 | // recalculez grad de echilibru pt nodul curent 116 | calculGENod(r); 117 | if (r->GE == 2) { 118 | if (r->dr->GE == -1) { 119 | //dezechilibru dreapta-stanga 120 | r = rotireDblDrSt(r, r->dr); 121 | } 122 | else { 123 | //dezechilibru dreapta 124 | r = rotireSimplaSt(r, r->dr); 125 | } 126 | } 127 | else { 128 | if (r->GE == -2) { 129 | if (r->st->GE == 1) { 130 | //dezechilibru combinat stanga-dreapta 131 | r = rotireDblStDr(r, r->st); 132 | } 133 | else { 134 | //dezechilibru stanga 135 | r = rotireSimplaDr(r, r->st); 136 | } 137 | } 138 | } 139 | 140 | return r; 141 | } 142 | 143 | 144 | // traversare AVL inordine 145 | void InordineAVL(NodAVL* rAVL) { 146 | if (rAVL) { 147 | InordineAVL(rAVL->st); 148 | printf(" cheie nod: %d grad de echilibru: %d \n", rAVL->stud.id, rAVL->GE); 149 | InordineAVL(rAVL->dr); 150 | } 151 | } 152 | 153 | int main() { 154 | struct Student stud; 155 | struct NodAVL* root = NULL; 156 | 157 | FILE* f; 158 | f = fopen("Studenti.txt", "r"); 159 | 160 | char* token, file_buf[LINESIZE], sep_list[] = ",\n"; 161 | 162 | while (fgets(file_buf, sizeof(file_buf), f)) { 163 | token = strtok(file_buf, sep_list); 164 | stud.id = atoi(token); 165 | 166 | token = strtok(NULL, sep_list); 167 | stud.nume = (char*)malloc((strlen(token) + 1) * sizeof(char)); 168 | strcpy(stud.nume, token); 169 | 170 | token = strtok(NULL, sep_list); 171 | stud.medie = (float)atof(token); 172 | 173 | token = strtok(NULL, sep_list); 174 | if (token) 175 | printf("\nEroare preluare token!"); 176 | 177 | // inserare student in AVL 178 | int err = 0; 179 | 180 | root = insNodAVL(root, stud, &err); 181 | if (err) { 182 | printf("\nStudentul cu id %d exista in arbore.\n", stud.id); 183 | free(stud.nume); 184 | } 185 | else 186 | printf("\nStudentul %s a fost inserat\n", stud.nume); 187 | } 188 | 189 | fclose(f); 190 | 191 | // traversare in inordine (ordine crescatoare id-uri studenti) 192 | printf("\nTraversare arbore AVL inordine:\n\n"); 193 | InordineAVL(root); 194 | 195 | return 0; 196 | } -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/13_AVL.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define LINESIZE 128 8 | 9 | struct Student { 10 | int id; 11 | char* nume; 12 | float medie; 13 | }; 14 | 15 | struct NodAVL { 16 | struct Student stud; 17 | char GE; 18 | struct NodAVL* st, * dr; 19 | }; 20 | 21 | typedef struct Student Student; 22 | typedef struct NodAVL NodAVL; 23 | 24 | 25 | // maximul a doi intregi 26 | int maxim(int a, int b) { 27 | return a > b ? a : b; 28 | } 29 | 30 | 31 | // inaltime (sub)arbore r 32 | int h(NodAVL* r) { 33 | if (r) 34 | return 1 + maxim(h(r->st), h(r->dr)); 35 | else 36 | return 0; 37 | } 38 | 39 | 40 | // gradul de echilibru al unui nod 41 | void calculGENod(NodAVL* r) { 42 | if (r) { 43 | //prelucrare (calcul GE) 44 | r->GE = h(r->dr) - h(r->st); 45 | } 46 | } 47 | 48 | 49 | // rotire simpla la dreapta 50 | NodAVL* rotireSimplaDr(NodAVL* pivot, NodAVL* fiuSt) { 51 | pivot->st = fiuSt->dr; // stanga pivotului devine subarbore Y (vezi curs) 52 | calculGENod(pivot); // recalculare GE pivot 53 | fiuSt->dr = pivot; // fiul pivotului promoveaza (dreapta devine pivot) pe nivel superior 54 | calculGENod(fiuSt); // recalculare GE fiu al pivotului 55 | 56 | return fiuSt; 57 | } 58 | 59 | // rotire simpla la stanga 60 | NodAVL* rotireSimplaSt(NodAVL* pivot, NodAVL* fiuDr) { 61 | pivot->dr = fiuDr->st; // dreapta pivot devine subarbore Y 62 | calculGENod(pivot); 63 | fiuDr->st = pivot; // fiul pivotului promoveaza (stanga sa devine pivot) pe nivel superior 64 | calculGENod(fiuDr); 65 | 66 | return fiuDr; 67 | } 68 | 69 | // rotire dubla stanga-dreapta 70 | NodAVL* rotireDblStDr(NodAVL* pivot, NodAVL* fiuSt) { 71 | //aducerea dezechilibrului pe aceeasi directie 72 | pivot->st = rotireSimplaSt(fiuSt, fiuSt->dr); // rotire de pregatire (efectuata in fiu stanga al pivotului care devine pivot la rotirea #1) 73 | calculGENod(pivot); 74 | fiuSt = pivot->st; // actualizare fiu stanga al pivotului 75 | //rotire propriu-zisa in pivot 76 | fiuSt = rotireSimplaDr(pivot, fiuSt); // dezechilibrul este pe aceeasi directie 77 | calculGENod(fiuSt); 78 | 79 | return fiuSt; 80 | } 81 | 82 | // rotire dubla dreapta-stanga 83 | NodAVL* rotireDblDrSt(NodAVL* pivot, NodAVL* fiuDr) { 84 | // aducerea dezechilibrului pe aceeasi directie 85 | pivot->dr = rotireSimplaDr(fiuDr, fiuDr->st); 86 | calculGENod(pivot); 87 | fiuDr = pivot->dr; 88 | // rotire propriu-zisa in pivot 89 | fiuDr = rotireSimplaSt(pivot, fiuDr); 90 | calculGENod(fiuDr); 91 | 92 | return fiuDr; 93 | } 94 | 95 | // inserare nod in AVL 96 | NodAVL* insNodAVL(NodAVL* r, Student s, int* err) { 97 | if (r) { 98 | if (r->stud.id > s.id) 99 | r->st = insNodAVL(r->st, s, err); 100 | else 101 | if (r->stud.id < s.id) 102 | r->dr = insNodAVL(r->dr, s, err); 103 | else 104 | *err = 1; 105 | } 106 | else { 107 | NodAVL* nou; 108 | nou = (NodAVL*)malloc(sizeof(NodAVL)); 109 | nou->stud = s; 110 | nou->st = NULL; 111 | nou->dr = NULL; 112 | r = nou; 113 | } 114 | 115 | // recalculez grad de echilibru pt nodul curent 116 | calculGENod(r); 117 | if (r->GE == 2) { 118 | if (r->dr->GE == -1) { 119 | //dezechilibru dreapta-stanga 120 | r = rotireDblDrSt(r, r->dr); 121 | } 122 | else { 123 | //dezechilibru dreapta 124 | r = rotireSimplaSt(r, r->dr); 125 | } 126 | } 127 | else { 128 | if (r->GE == -2) { 129 | if (r->st->GE == 1) { 130 | //dezechilibru combinat stanga-dreapta 131 | r = rotireDblStDr(r, r->st); 132 | } 133 | else { 134 | //dezechilibru stanga 135 | r = rotireSimplaDr(r, r->st); 136 | } 137 | } 138 | } 139 | 140 | return r; 141 | } 142 | 143 | 144 | // traversare AVL inordine 145 | void InordineAVL(NodAVL* rAVL) { 146 | if (rAVL) { 147 | InordineAVL(rAVL->st); 148 | printf(" cheie nod: %d grad de echilibru: %d \n", rAVL->stud.id, rAVL->GE); 149 | InordineAVL(rAVL->dr); 150 | } 151 | } 152 | 153 | int main() { 154 | struct Student stud; 155 | struct NodAVL* root = NULL; 156 | 157 | FILE* f; 158 | f = fopen("Studenti.txt", "r"); 159 | 160 | char* token, file_buf[LINESIZE], sep_list[] = ",\n"; 161 | 162 | while (fgets(file_buf, sizeof(file_buf), f)) { 163 | token = strtok(file_buf, sep_list); 164 | stud.id = atoi(token); 165 | 166 | token = strtok(NULL, sep_list); 167 | stud.nume = (char*)malloc((strlen(token) + 1) * sizeof(char)); 168 | strcpy(stud.nume, token); 169 | 170 | token = strtok(NULL, sep_list); 171 | stud.medie = (float)atof(token); 172 | 173 | token = strtok(NULL, sep_list); 174 | if (token) 175 | printf("\nEroare preluare token!"); 176 | 177 | // inserare student in AVL 178 | int err = 0; 179 | 180 | root = insNodAVL(root, stud, &err); 181 | if (err) { 182 | printf("\nStudentul cu id %d exista in arbore.\n", stud.id); 183 | free(stud.nume); 184 | } 185 | else 186 | printf("\nStudentul %s a fost inserat\n", stud.nume); 187 | } 188 | 189 | fclose(f); 190 | 191 | // traversare in inordine (ordine crescatoare id-uri studenti) 192 | printf("\nTraversare arbore AVL inordine:\n\n"); 193 | InordineAVL(root); 194 | 195 | return 0; 196 | } -------------------------------------------------------------------------------- /2024-2025/SeriaCSol/SeriaCProj/10_StructHeap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define DIM 20 7 | 8 | 9 | void inserare_cheie_heap(int* strHeap, int* strSize, int key) 10 | { 11 | *strSize += 1; // se actualizeaza numarul de noduri din structura (nr efectiv de chei din struct Heap) 12 | int offs_key = *strSize - 1; // offset nod/cheie care se inseareaza in structura Heap 13 | strHeap[offs_key] = key; // se scrie cheia de inserat in structura Heap 14 | 15 | int offs_parinte = (offs_key - 1) / 2; 16 | 17 | while (strHeap[offs_key] > strHeap[offs_parinte]) 18 | { 19 | // interschimbare key-parinte 20 | int aux = strHeap[offs_key]; 21 | strHeap[offs_key] = strHeap[offs_parinte]; 22 | strHeap[offs_parinte] = aux; 23 | 24 | // actualizare offset key in vector 25 | offs_key = offs_parinte; 26 | 27 | // calcul offset parinte nou pentru key 28 | offs_parinte = (offs_key - 1) / 2; 29 | } 30 | } 31 | 32 | 33 | int stergere_cheie_heap(int* strHeap, int* strSize) 34 | { 35 | int key; // cheie nod care se sterge din structura Heap 36 | int offs_key = 0; // offset nod radacina; locul de unde se pleaca in procesul de cautare a pozitiei finale 37 | int max = 0; 38 | //preiau ultimul element din structura 39 | int lastElement = strHeap[*strSize - 1]; 40 | key = strHeap[0]; 41 | strHeap[0] = lastElement; 42 | 43 | *strSize -= 1; // actualizare dimensiune efectiva a vectorului (nr de chei din structura Heap) 44 | 45 | int Left = 2 * offs_key + 1; 46 | int Right = 2 * offs_key + 2; 47 | 48 | if ((Left < *strSize) && (Right < *strSize)) 49 | { 50 | // exista ambii descendenti pentru offs_key 51 | if (strHeap[Left] > strHeap[Right]) 52 | { 53 | max = Left; // nodul din stanga are cheie mai mare decat cel din dreapta 54 | } 55 | else 56 | { 57 | max = Right; // nodul din dreapta are cheie mai mare decat cel din stanga 58 | } 59 | } 60 | else 61 | { 62 | if (Left < *strSize) 63 | { 64 | // exista un singur descendent pentru nodul offs_key (obligatoriu este descendent stanga deoarece arborele este binar complet) 65 | max = Left; 66 | } 67 | } 68 | 69 | while ((*strSize > 0) && (strHeap[max] > lastElement)) 70 | { 71 | // relatia de ordine nu este corecta pentru un max-heap 72 | // interschimbare cheie cu descendentul cu cheia maxima 73 | int aux = strHeap[offs_key]; 74 | strHeap[offs_key] = strHeap[max]; 75 | strHeap[max] = aux; 76 | 77 | // actualizare offset cheie care coboara in arbore 78 | offs_key = max; 79 | 80 | 81 | Left = 2 * offs_key + 1; 82 | Right = 2 * offs_key + 2; 83 | if ((Left < *strSize) && (Right < *strSize)) 84 | { 85 | if (strHeap[Left] > strHeap[Right]) 86 | { 87 | max = Left; 88 | } 89 | else 90 | { 91 | max = Right; 92 | } 93 | } 94 | else 95 | { 96 | if (Left < *strSize) 97 | { 98 | max = Left; 99 | } 100 | } 101 | } 102 | 103 | return key; 104 | } 105 | 106 | 107 | 108 | int main() 109 | { 110 | int* strHeap = NULL; // variabila acces la structura Heap 111 | 112 | strHeap = (int*)malloc(DIM * sizeof(int)); 113 | int capacitate_stocare = DIM; // nr max de chei stocat de structura heap (arbore binar complet) 114 | 115 | int nKeys = 0, cheie; // numarul de chei disponibile in structura Heap la un moment dat 116 | 117 | FILE* f; 118 | f = fopen("HeapKeys.txt", "r"); 119 | 120 | fscanf(f, "%d", &cheie); 121 | while (!feof(f)) 122 | { 123 | if (nKeys == capacitate_stocare) 124 | { 125 | // realocare vector cu + DIM elemente 126 | // se copiaza elementele din vechea structura in noua structura pe exact aceleasi pozitii 127 | capacitate_stocare += DIM; 128 | int* new_strHeap = (int*)malloc(capacitate_stocare * sizeof(DIM)); 129 | for (int i = 0; i < nKeys; i++) 130 | new_strHeap[i] = strHeap[i]; // se copiaza cheile de pe structura curenta pe structura noua 131 | 132 | // dezalocare vector la capacitate maxima 133 | free(strHeap); 134 | // comutare pointer pe noua locatie extinsa 135 | strHeap = new_strHeap; 136 | } 137 | 138 | inserare_cheie_heap(strHeap, &nKeys, cheie); 139 | 140 | fscanf(f, "%d", &cheie); 141 | } 142 | 143 | printf("\n Structura Heap initiala: "); 144 | for (int i = 0; i < nKeys; i++) 145 | printf(" %d ", strHeap[i]); 146 | 147 | // inserare cheie 26 in structura Heap 148 | inserare_cheie_heap(strHeap, &nKeys, 26); 149 | 150 | printf("\n\n Structura Heap dupa inserare cheie 26: "); 151 | for (int i = 0; i < nKeys; i++) 152 | printf(" %d ", strHeap[i]); 153 | printf("\n"); 154 | 155 | cheie = stergere_cheie_heap(strHeap, &nKeys); 156 | printf("\n\n Structura Heap dupa stergere cheie radacina: "); 157 | for (int i = 0; i < nKeys; i++) 158 | printf(" %d ", strHeap[i]); 159 | printf("\n"); 160 | 161 | 162 | // prelucrare date/chei in ordine descrescatoare prin stergere repetata a nodului radacina 163 | printf("Stergere chei din structura Heap (prelucrare chei in ordine descrescatoare): "); 164 | while (nKeys > 0) 165 | { 166 | printf(" %d ", stergere_cheie_heap(strHeap, &nKeys)); 167 | } 168 | printf("\n\n"); 169 | 170 | // dezalocare vector suport structura max-heap 171 | free(strHeap); 172 | 173 | fclose(f); 174 | return 0; 175 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1075Sol/Grupa1075Proj/04_SimpleLists.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define CARD_NUMBER_SIZE 16 7 | #define CARD_ARRAY_SIZE 20 8 | 9 | struct Date 10 | { 11 | char month; // stored as value 12 | char year; // stored as value; only last 2 letters are stored 13 | }; 14 | 15 | typedef struct Date Date; 16 | 17 | struct BankCard 18 | { 19 | char* holder; // 4 bytes 20 | char card_no[CARD_NUMBER_SIZE + 1]; // 17 bytes 21 | Date exp_date; // 2 bytes -> no alignment (month and year are char) 22 | char* issuer; // 4 bytes -> enforce alignment by adding +1 byte to card_no 23 | float balance; // 4 bytes 24 | }; // 31 bytes (sum of all structure fields); actual length is 32 bytes 25 | 26 | typedef struct BankCard BankCard; 27 | 28 | struct Node 29 | { 30 | BankCard data; 31 | struct Node* next; // the mem address of the next item (node) in the chain 32 | }; 33 | 34 | typedef struct Node Node; 35 | 36 | // insert one node into a simple list after an existing holder's name 37 | // if list is empty, then perform the operation 38 | // if there is no node with the holder's name, drop off the insert opeation 39 | Node* insert_node(Node* list, BankCard bc, char * holder_name) 40 | { 41 | if (list == NULL) 42 | { 43 | // the list is empty 44 | Node* new_node = malloc(sizeof(Node)); 45 | new_node->data = bc; 46 | new_node->next = NULL; 47 | list = new_node; 48 | } 49 | else 50 | { 51 | // the list contains one node at least 52 | Node* temp = list; // temp used to parse the list node by node 53 | char stop_parsing_flag = 0; 54 | while (temp != NULL && stop_parsing_flag == 0) 55 | { 56 | if (strcmp(temp->data.holder, holder_name) == 0) 57 | { 58 | // the node with the holders' name has been found out in the list (temp) 59 | Node* new_node = malloc(sizeof(Node)); 60 | new_node->data = bc; 61 | new_node->next = temp->next; 62 | temp->next = new_node; 63 | stop_parsing_flag = 1; 64 | } 65 | 66 | temp = temp->next; 67 | } 68 | 69 | if (stop_parsing_flag == 0) 70 | { 71 | // the insert did not take place; we have to deallocate fields holder and issuer in card data bc 72 | free(bc.holder); 73 | free(bc.issuer); 74 | } 75 | } 76 | 77 | return list; // updated when the list is coming empty to this call 78 | } 79 | 80 | // parsing the simple list to print out content from node 81 | void parse(Node* list) 82 | { 83 | Node* temp = list; 84 | while (temp != NULL) 85 | { 86 | printf("%s %s\n", temp->data.holder, temp->data.card_no); 87 | temp = temp->next; 88 | } 89 | } 90 | 91 | Node* delete_node_beginning(Node* list) 92 | { 93 | if (list != NULL) 94 | { 95 | // there is one node at least in the simple list 96 | Node* temp = list; // save the node to be deallocated/deleted 97 | list = list->next; // the new starting node of the remaining lis 98 | // list = temp->next; 99 | 100 | free(temp->data.holder); // deallocate the holder's heap mem 101 | free(temp->data.issuer); // deallocate the issuer's heap mem 102 | free(temp); // deallocate the node itself 103 | } 104 | 105 | return list; 106 | } 107 | 108 | // function to delete all nodes having the same card holder (parameter of the function) 109 | // within a simple list 110 | 111 | int main() 112 | { 113 | FILE* f = fopen("CardData.txt", "r"); 114 | Node* list_start = NULL; 115 | 116 | unsigned char buffer[200]; 117 | 118 | fgets(buffer, sizeof(buffer), f); 119 | while (!feof(f)) 120 | { 121 | BankCard card; 122 | char seps[] = ",/\n"; 123 | char* token = strtok(buffer, seps); 124 | card.holder = malloc(strlen(token) + 1); // +1 for null byte as terminator 125 | strcpy(card.holder, token); // copy the string token into v_card holder's heap area 126 | 127 | token = strtok(NULL, seps); // get the vard number string 128 | strcpy(card.card_no, token); 129 | 130 | token = strtok(NULL, seps); // get the month 131 | card.exp_date.month = atoi(token); // convert string month into integer month 132 | token = strtok(NULL, seps); // get the year 133 | card.exp_date.year = atoi(token); // convert string year into integer year 134 | 135 | token = strtok(NULL, seps); 136 | card.issuer = malloc(strlen(token) + 1); 137 | strcpy(card.issuer, token); 138 | 139 | token = strtok(NULL, seps); // get the balance 140 | card.balance = (float)atof(token); // convert string balance into float balance 141 | 142 | // insert card data into a simple list 143 | list_start = insert_node(list_start, card, "Popescu Marian Alexandru"); 144 | 145 | // read the next line in the text file CardData.txt 146 | fgets(buffer, sizeof(buffer), f); 147 | } 148 | 149 | fclose(f); 150 | 151 | printf("Simple list after its creation\n"); 152 | parse(list_start); 153 | 154 | list_start = delete_node_beginning(list_start); 155 | printf("\nSimple list after node delete:\n"); 156 | parse(list_start); 157 | 158 | // deallocation of entire simple list with repeated calls to delete_node_beginning(list_start) 159 | 160 | 161 | // migrate all above functions to double lists 162 | 163 | 164 | // insert a node into a simple list (at the end, in the middle) 165 | // delete a node in a simple list (at the end, in the middle) 166 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/10_Struct_Heap.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | 6 | #define CAPACITATE_STOCARE_HEAP 10 7 | 8 | 9 | int* realocare_structura_heap(int* heap_agregat, unsigned char* capacitate_heap_agregat, unsigned char nr_eleme_aditionale) 10 | { 11 | unsigned char nr_chei = *capacitate_heap_agregat; 12 | *capacitate_heap_agregat += nr_eleme_aditionale; 13 | int* new_heap = malloc(*capacitate_heap_agregat * sizeof(int)); // alocare vector cu capacitate mai mare 14 | 15 | for (unsigned char i = 0; i < nr_chei; i++) 16 | { 17 | new_heap[i] = heap_agregat[i]; 18 | } 19 | 20 | free(heap_agregat); // dezalocare structura heap curenta 21 | return new_heap; // noul vector este returnat in apelator unde heap_agregat se rescrie cu noua adresa 22 | } 23 | 24 | int* agregare_structuri_heap(int cheie_noua, int* heap1, unsigned char size_heap1, 25 | int* heap2, unsigned char size_heap2, 26 | int* heap_agregat, unsigned char *size_heap_agregat, 27 | unsigned char* capacitate_heap_agregat) 28 | { 29 | heap_agregat = malloc(*capacitate_heap_agregat * sizeof(int)); // alocare initiala pentru structura heap rezultata 30 | 31 | unsigned char i = 0; // offset in heap1 32 | unsigned char j = 0; // offset in heap2 33 | unsigned char k = 0; // offset in heap_agregat 34 | 35 | heap_agregat[k++] = cheie_noua; // scriere cheie in radacina heap agregat 36 | *size_heap_agregat += 1; // incrementare numar de chei din structura heap 37 | 38 | // validare structura stanga mai mare decat cea din dreapta la agregare 39 | if (size_heap1 < size_heap2) 40 | { 41 | // structura dreapta este mai mare 42 | 43 | // intreschimb de structuri la nivel de vectori si dimensiuni 44 | int* paux = heap1; 45 | heap1 = heap2; 46 | heap2 = paux; 47 | 48 | unsigned char daux = size_heap1; 49 | size_heap1 = size_heap2; 50 | size_heap2 = daux; 51 | } 52 | 53 | unsigned char nr_h = 1; // nr chei de pe nivel h: 1 cheie pe nivel 1 54 | unsigned char gata = 1; 55 | while (gata) 56 | { 57 | unsigned char l = i; // l - numar de chei copiate in heap agregat in iteratiile anterioare 58 | // traversare nivel h din heap 1 si copiere chei in heap_agregat 59 | for (; i < size_heap1 && i < nr_h + l; i++) // i offset curent in heap1 60 | { 61 | heap_agregat[k++] = heap1[i]; // copiere element din heap 1 in offset curent heap_agregat 62 | *size_heap_agregat += 1; 63 | if (*size_heap_agregat == *capacitate_heap_agregat) 64 | { 65 | heap_agregat = realocare_structura_heap(heap_agregat, capacitate_heap_agregat, 66 | CAPACITATE_STOCARE_HEAP); 67 | } 68 | } 69 | 70 | 71 | // traversare nivel h din heap 2 si copiere chei in heap_agregat 72 | for (; j < size_heap2 && j < nr_h + l; j++) // j offset curent in heap2 73 | { 74 | heap_agregat[k++] = heap2[j]; // copiere element din heap 2 in offset curent heap_agregat 75 | *size_heap_agregat += 1; 76 | if (*size_heap_agregat == *capacitate_heap_agregat) 77 | { 78 | heap_agregat = realocare_structura_heap(heap_agregat, capacitate_heap_agregat, 79 | CAPACITATE_STOCARE_HEAP); 80 | } 81 | } 82 | 83 | if (i >= size_heap1 && j >= size_heap2) 84 | gata = 0; // nu mai exista elemente de adus din cele doua structuri heap de intrare in agregare 85 | nr_h = nr_h * 2; // numarul de chei de pe nivelul urmator accesat in interatia urmatoare 86 | } 87 | 88 | 89 | return heap_agregat; 90 | } 91 | 92 | int main() 93 | { 94 | int struct_heap1[] = {32, 12, 24, 7, 9, 17}; 95 | int struct_heap2[] = {8, 2, 3}; 96 | 97 | int* heap_rezultat = NULL; 98 | unsigned char capacitate_heap = CAPACITATE_STOCARE_HEAP; // capacitate de stocare initiala pentru heap_rezultat 99 | unsigned char nr_noduri_heap = 0; // nr de chei stocate de heap_rezultat 100 | 101 | // 1. cele doua structuri de intrare trebuie sa aiba o diferenta de inaltime de maxim 1 nivel pentru a obtine 102 | // o structura agregata ca arbore binar complet 103 | // 2. este posibil ca structura din dreapta sa fie mai inalta (max 1 nivel) fata de cea din stanga. 104 | // cele doua structuri heap de intrare se interschimba pentru a avea un arbore binar complet pe structura rezultata 105 | // (rezolvare: vezi implementare agregare_structuri_heap) 106 | 107 | //heap_rezultat = agregare_structuri_heap(23, struct_heap1, sizeof(struct_heap1) / sizeof(int), 108 | // struct_heap2, sizeof(struct_heap2) / sizeof(int), 109 | // heap_rezultat, &nr_noduri_heap, &capacitate_heap); 110 | 111 | heap_rezultat = agregare_structuri_heap(23, struct_heap2, sizeof(struct_heap2) / sizeof(int), 112 | struct_heap1, sizeof(struct_heap1) / sizeof(int), 113 | heap_rezultat, &nr_noduri_heap, &capacitate_heap); 114 | 115 | printf("Vector structura heap dupa agregare: "); 116 | for (unsigned char i = 0; i < nr_noduri_heap; i++) 117 | { 118 | printf("%d ", heap_rezultat[i]); 119 | } 120 | printf("\n"); 121 | 122 | // structura este cea corespunzatoare figurii a din suport de curs 123 | // cheia din nodul radacina trebuie sa fie validata in raport cu descendentii sai prin filtrarea top-down 124 | // vezi suport de curs operatie de stergere radacina din arbore Heap !!! pentru a duce structura Heap agregata 125 | // in situatia prezentata de figura c) din slide suport de curs 126 | 127 | return 0; 128 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/05_ListeDuble.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define NR_CIFRE_CARD 16 9 | #define DIM_MONEDA 3 10 | 11 | struct DataExpirare 12 | { 13 | unsigned short int anul; 14 | unsigned char luna; 15 | }; 16 | 17 | typedef struct DataExpirare DataExpirare; 18 | 19 | struct CardBancar 20 | { 21 | char nr_card[NR_CIFRE_CARD + 1]; // +1 pentru terminatot de string util in cazul utilizarii ca string 22 | char* titular; 23 | DataExpirare data; 24 | float sold; 25 | char moneda[DIM_MONEDA + 1]; // RON, EUR, USD 26 | }; 27 | 28 | typedef struct CardBancar CardBancar; 29 | 30 | struct NodD 31 | { 32 | CardBancar card; 33 | struct NodD* next, *prev; 34 | }; 35 | 36 | typedef struct NodD NodD; 37 | 38 | struct ListaDubla 39 | { 40 | NodD* prim, * ultim; 41 | }; 42 | 43 | typedef struct ListaDubla ListaDubla; 44 | 45 | // inserare nod la sfarsitul listei duble 46 | ListaDubla inserare_sfarsit(ListaDubla lista, CardBancar data) 47 | { 48 | NodD* nou = malloc(sizeof(NodD)); 49 | nou->card = data; 50 | nou->next = NULL; // succesor NULL tot timpul pentru nou 51 | nou->prev = lista.ultim; // predecesor ultim curent 52 | 53 | if (lista.ultim == NULL) 54 | { 55 | // lista nu contine nici un nod 56 | // nou devine primul, ultimul si unicul nod in lista dubla 57 | lista.prim = nou; 58 | } 59 | else 60 | { 61 | lista.ultim->next = nou; // sfarsitul curent va avea succesor pe nou 62 | } 63 | lista.ultim = nou; // actualizare sfarsit curent de lista dubla 64 | 65 | return lista; // actualizare capete de acces la lista dubla 66 | } 67 | 68 | 69 | // traversare lista dubla in ambele sensuri 70 | void traversare_listadubla(ListaDubla lista) 71 | { 72 | NodD* temp = lista.prim; 73 | printf("Lista dubla traversare prim->ultim:\n"); 74 | while (temp != NULL) 75 | { 76 | printf("%s %s\n", temp->card.nr_card, temp->card.titular); 77 | temp = temp->next; 78 | } 79 | temp = lista.ultim; 80 | printf("Lista dubla traversare ultim->prim:\n"); 81 | while (temp != NULL) 82 | { 83 | printf("%s %s\n", temp->card.nr_card, temp->card.titular); 84 | temp = temp->prev; 85 | } 86 | } 87 | 88 | void traversare_recursiv(NodD* temp) 89 | { 90 | if (temp != NULL) 91 | { 92 | printf("%s %s\n", temp->card.nr_card, temp->card.titular); 93 | traversare_recursiv(temp->next); // apel recursiv pentru nodul succesor 94 | } 95 | } 96 | 97 | // stergere nod la inceputul listei duble 98 | ListaDubla stergere_inceput(ListaDubla lista) 99 | { 100 | if (lista.prim != NULL) 101 | { 102 | // exista cel putin 1 nod in lista dubla 103 | NodD* temp = lista.prim; 104 | if (lista.prim->next == NULL) 105 | { 106 | // exista un singur nod in lista dubla fiind deja salvat in temp 107 | lista.prim = NULL; // lista devine empty 108 | lista.ultim = NULL; // lista devine empty 109 | } 110 | else 111 | { 112 | // cel putin 2 noduri in lista dubla 113 | lista.prim = lista.prim->next; // noul inceput de lista dubla este nodul #2 114 | lista.prim->prev = NULL; // nodul #2 devine inceput de lista dubla, deci nu are predecesor 115 | } 116 | 117 | free(temp->card.titular); // dezalocare string pentru titular 118 | free(temp); // dezalocare nod lista dubla 119 | } 120 | 121 | return lista; 122 | } 123 | 124 | // traversare recursiva ultim->prim 125 | 126 | // stergere noduri din lista dubla pe baza anului expirarii cardului 127 | 128 | // functie interschimbare noduri oarecare din lista dubla 129 | 130 | // functie sortare noduri lista dubla 131 | 132 | // functie stergere nod de pe pozitia i in lista dubla 133 | // datele cardului bancar sunt "salvate"/returnate in vederea utilizarii ulterioare 134 | // (stergere cu extragerea datelor din nod) 135 | 136 | 137 | int main() 138 | { 139 | FILE* f = NULL; 140 | f = fopen("CarduriBancare.txt", "r"); 141 | 142 | char buffer[200]; 143 | CardBancar card; 144 | ListaDubla listaD; 145 | listaD.prim = NULL; 146 | listaD.ultim = NULL; 147 | 148 | fgets(buffer, sizeof(buffer), f); 149 | while (!feof(f)) 150 | { 151 | strtok(buffer, "\n"); 152 | strcpy(card.nr_card, buffer); 153 | 154 | fgets(buffer, sizeof(buffer), f); 155 | strtok(buffer, "\n"); 156 | card.titular = malloc(strlen(buffer) + 1); // +1 terminator de string 157 | strcpy(card.titular, buffer); 158 | 159 | fgets(buffer, sizeof(buffer), f); 160 | strtok(buffer, "\n"); 161 | sscanf(buffer, "%hu%hhu", &card.data.anul, &card.data.luna); 162 | 163 | fgets(buffer, sizeof(buffer), f); 164 | strtok(buffer, "\n"); 165 | card.sold = (float)atof(buffer); 166 | 167 | fgets(buffer, sizeof(buffer), f); 168 | strtok(buffer, "\n"); 169 | strcpy(card.moneda, buffer); 170 | 171 | // inserare date card bancar in lista dubla 172 | listaD = inserare_sfarsit(listaD, card); 173 | 174 | fgets(buffer, sizeof(buffer), f); 175 | } 176 | fclose(f); 177 | 178 | printf("Lista dubla dupa creare:\n"); 179 | traversare_listadubla(listaD); 180 | printf("\n\nLista dubla dupa creare (traversare versiune recursiva)\n"); 181 | traversare_recursiv(listaD.prim); 182 | 183 | listaD = stergere_inceput(listaD); 184 | printf("\n\nLista dubla dupa stergerea unui nod:\n"); 185 | traversare_listadubla(listaD); 186 | 187 | while (listaD.prim != NULL) 188 | { 189 | listaD = stergere_inceput(listaD); 190 | } 191 | printf("\n\nLista dubla dupa dezalocare:\n"); 192 | traversare_listadubla(listaD); 193 | 194 | return 0; 195 | } -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/11_ArboriO.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct NodTree { 5 | int key; 6 | struct NodTree* fiu, * frate; 7 | }; 8 | 9 | 10 | // r - nod curent in apelul recursiv i 11 | // id - cheia nodului cautat in AO 12 | // gasit - adresa nodului care contine id in AO; trensferat prin adresa 13 | void cautaNod(struct NodTree* r, int id, struct NodTree** gasit) { 14 | // cautare recursiva a unui nod cu cheie id in arbore oarecare 15 | // operatie de traversare in preordine cu verificarea continutului 16 | // nodului curent r 17 | if (r) { 18 | printf("Nod curent este: %d\n", r->key); 19 | if (r->key == id) { // prelucrez nodul curent r 20 | *gasit = r; 21 | return; 22 | } 23 | cautaNod(r->fiu, id, gasit); // parsez primul subarbore descendent lui r 24 | if (*gasit) 25 | return; 26 | if (r->fiu) { 27 | struct NodTree* tmp = r->fiu; 28 | while (tmp->frate) { // parsez restul de subarbori descendenti lui r 29 | cautaNod(tmp->frate, id, gasit); 30 | if (*gasit) 31 | return; 32 | tmp = tmp->frate; 33 | } 34 | } 35 | } 36 | } 37 | 38 | 39 | void preordine(struct NodTree* r) { 40 | if (r) { 41 | printf("%d ", r->key); 42 | 43 | preordine(r->fiu); // parsez primul subarbore descendent lui r 44 | 45 | if (r->fiu) { 46 | struct NodTree* tmp = r->fiu; 47 | while (tmp->frate) { // parsez restul de subarbori descendenti lui r 48 | preordine(tmp->frate); 49 | tmp = tmp->frate; 50 | } 51 | } 52 | } 53 | } 54 | 55 | struct NodTree* dezalocare_AO_postordine(struct NodTree* r) { 56 | if (r != NULL) { 57 | r->fiu = dezalocare_AO_postordine(r->fiu); 58 | struct NodTree* temp = r->frate; // salvare prim frate pentru r (inceput lista de frati) 59 | printf("Dezalocare nod cu cheia %d\n", r->key); 60 | free(r); 61 | r = NULL; 62 | 63 | while (temp != NULL) { 64 | temp->fiu = dezalocare_AO_postordine(temp->fiu); // dezalocare subarbori pentru nodul temp 65 | struct NodTree* t_frate = temp; // salvare temporara inceput de lista de fratie in vederea dezalocarii 66 | temp = temp->frate; // temp este urmatorul nod in lista de frati 67 | printf("Dezalocare nod cu cheia %d\n", t_frate->key); 68 | free(t_frate); // dezalocare inceput lista frati pentru care s-au dezalocat toti subarborii 69 | } 70 | } 71 | 72 | return r; 73 | } 74 | 75 | // r - nod radacina AO 76 | // cheie - cheie nodului care se insereaza in AO 77 | // idParinte - cheie nod care devine parinte pentru nodul de inserat cu cheie 78 | struct NodTree* inserare(struct NodTree* r, int cheie, int idParinte) { 79 | 80 | if (!idParinte) { // nodul nou (cu cheie) va deveni noua radacina de arbore 81 | struct NodTree* nou = (struct NodTree*)malloc(sizeof(struct NodTree)); // nodul care se insereaza devine nod radacina 82 | nou->key = cheie; 83 | nou->fiu = NULL; 84 | nou->frate = NULL; 85 | 86 | if (r) { 87 | nou->fiu = r; 88 | } 89 | 90 | r = nou; 91 | } 92 | else { // se cauta nodul cu idParinte care va primi descendent pe nou cu cheie 93 | struct NodTree* nou = (struct NodTree*)malloc(sizeof(struct NodTree)); 94 | nou->key = cheie; 95 | nou->fiu = NULL; 96 | nou->frate = NULL; 97 | 98 | struct NodTree* p = NULL; 99 | 100 | cautaNod(r, idParinte, &p); // cautare nod cu cheie idParinte; p pointer trimis prin adresa 101 | 102 | if (p && !p->fiu) // nodul parinte nu are descendenti 103 | p->fiu = nou; // nou devine primul fiu pentru parintele identificat p 104 | else { 105 | if (p) 106 | { 107 | // nodul parinte exista in AO 108 | if (!p->fiu->frate) 109 | p->fiu->frate = nou; // nou devine primul frate (nodul 2 din lista de descendenti pentru parintele p) 110 | else { 111 | struct NodTree* tmp = p->fiu; 112 | while (tmp->frate) 113 | tmp = tmp->frate; // nou devine ultimul nod din lista de descendenti ai parintelui p 114 | 115 | tmp->frate = nou; 116 | } 117 | } 118 | else 119 | { 120 | ; // nodul nou cu cheie nu se insereaza in AO daca parintele p nu este gasit (p == NULL) 121 | } 122 | } 123 | } 124 | 125 | return r; 126 | } 127 | 128 | void main() { 129 | struct NodTree* root = NULL; 130 | 131 | // inserare cheie in arbore 132 | printf("\nInserare NOD cheie 1:\n"); 133 | root = inserare(root, 1, 0); 134 | printf("\nInserare NOD cheie 2:\n"); 135 | root = inserare(root, 2, 1); 136 | printf("\nInserare NOD cheie 3:\n"); 137 | root = inserare(root, 3, 1); 138 | printf("\nInserare NOD cheie 4:\n"); 139 | root = inserare(root, 4, 1); 140 | printf("\nInserare NOD cheie 5:\n"); 141 | root = inserare(root, 5, 2); 142 | printf("\nInserare NOD cheie 6:\n"); 143 | root = inserare(root, 6, 2); 144 | printf("\nInserare NOD cheie 7:\n"); 145 | root = inserare(root, 7, 6); 146 | printf("\nInserare NOD cheie 8:\n"); 147 | root = inserare(root, 8, 7); 148 | 149 | printf("\nArborele in traversare in preordine:\n\n"); 150 | preordine(root); 151 | printf("\n\n"); 152 | 153 | printf("\nInserare NOD cheie 9:\n"); 154 | root = inserare(root, 9, 7); 155 | // root = inserare(root, 9, 0); // nodul cu cheie 9 devine noua radacina de AO 156 | // root = inserare(root, 9, 17); // nodul cu cheie 17 nu exista in AO, nodul cu cheie 9 nu se insereaza 157 | 158 | printf("\nArborele in traversare in preordine:\n\n"); 159 | preordine(root); 160 | 161 | printf("\nDezalocare Arbore Oarecare:\n"); 162 | root = dezalocare_AO_postordine(root); 163 | 164 | printf("\nArborele in traversare in preordine dupa dezalocare:\n\n"); 165 | preordine(root); 166 | 167 | printf("\n\n"); 168 | } -------------------------------------------------------------------------------- /2024-2025/SeriaDSol/SeriaDProj/08_Heap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define DIM 7 7 | 8 | // cautare si plasare cheie inserata intr-un max-heap 9 | // strHeap - vectorul de chei din structura Heap (transfer prin valoare) 10 | // strSize - numarul de noduri/chei din structura Heap (transfer prin adresa) 11 | // key - cheie de inserat in structura Heap (transfer) 12 | void inserare_cheie_heap(int* strHeap, int* strSize, int key) 13 | { 14 | *strSize += 1; // incrementare dimensiune structura Heap (vector) 15 | int offs_key = *strSize - 1; // offset initial pt key (cheie de inserat in structura) -> i 16 | strHeap[offs_key] = key; // stocare key (cheie noua) in arbore/structura Heap 17 | 18 | int offs_parinte = (offs_key - 1) / 2; // calcul offset parinte -> offset calculat j 19 | 20 | while (strHeap[offs_key] > strHeap[offs_parinte]) // (in)validare pozitia lui key in arbore 21 | { 22 | // interschimb cheie inserata (key) cu cheie parinte 23 | int aux = strHeap[offs_key]; 24 | strHeap[offs_key] = strHeap[offs_parinte]; 25 | strHeap[offs_parinte] = aux; 26 | 27 | // modificare offset cheie inserata (dupa interschimb cu parinte) 28 | offs_key = offs_parinte; 29 | 30 | offs_parinte = (offs_key - 1) / 2; // recalculare offset parinte pentru cheie inserata (key) 31 | } 32 | } 33 | 34 | 35 | int stergere_cheie_heap(int* strHeap, int* strSize) 36 | { 37 | int key; 38 | int offs_key = 0; 39 | int max = 0; 40 | 41 | int lastElement = strHeap[*strSize - 1]; // ultimul nod din arbore Heap 42 | key = strHeap[0]; // cheia din nodul radacina al struct Heap 43 | strHeap[0] = lastElement; // rescriere nod radacina cu cheia ultimului nod de pe ultimul nivel 44 | 45 | *strSize -= 1; // actualizare nr de noduri/chei din arbore Heap 46 | 47 | int Left = 2 * offs_key + 1; // descendent stanga initial pentru noua radacina (lastElement/strHeap[0]) 48 | int Right = 2 * offs_key + 2; // descendent dreapata initial pentru noua radacina (lastElement/strHeap[0]) 49 | 50 | if ((Left < *strSize) && (Right < *strSize)) // exista ambii descendenti pt noua radacina 51 | { 52 | if (strHeap[Left] > strHeap[Right]) // determinare descendent cu cheia maxima 53 | { 54 | max = Left; 55 | } 56 | else 57 | { 58 | max = Right; 59 | } 60 | } 61 | else // 0 sau 1 descendent pentru noua radacina 62 | { 63 | if (Left < *strSize) 64 | { 65 | max = Left; // maxim este unicul descendent 66 | } 67 | } 68 | 69 | while ((*strSize > 0) && (strHeap[max] > lastElement)) // lastElement nu respecta relatia de ordine cu descendentii 70 | { 71 | // interschimb lastElement cu descendentul cu cheia maxima 72 | int aux = strHeap[offs_key]; 73 | strHeap[offs_key] = strHeap[max]; 74 | strHeap[max] = aux; 75 | 76 | // actualizare offset lastElement 77 | offs_key = max; 78 | 79 | // re-calculare descendenti pentru noul offset al lui lastElement 80 | Left = 2 * offs_key + 1; 81 | Right = 2 * offs_key + 2; 82 | if ((Left < *strSize) && (Right < *strSize)) 83 | { 84 | if (strHeap[Left] > strHeap[Right]) 85 | { 86 | max = Left; 87 | } 88 | else 89 | { 90 | max = Right; 91 | } 92 | } 93 | else 94 | { 95 | if (Left < *strSize) 96 | { 97 | max = Left; 98 | } 99 | } 100 | } 101 | 102 | return key; 103 | } 104 | 105 | 106 | int main() 107 | { 108 | int* strHeap = NULL; // vector stocare chei din structura Heap 109 | 110 | strHeap = (int*)malloc(DIM * sizeof(int)); // alocare vector suport pe capacitate initiala DIM 111 | int capacitate_stocare = DIM; // capacitate de stocare (nr maxim de chei stocat) initiala 112 | 113 | int nKeys = 0, cheie; // nKeys - nr. de chei din structura Heap la un moment 114 | 115 | FILE* f; 116 | f = fopen("HeapKeys.txt", "r"); 117 | 118 | fscanf(f, "%d", &cheie); 119 | while (!feof(f)) 120 | { 121 | if (nKeys == capacitate_stocare) // nr de noduri este la capacitate max de stocare in vector 122 | { 123 | // realocare vector pe capacitate mai mare 124 | capacitate_stocare += DIM; 125 | int* new_strHeap = (int*)malloc(capacitate_stocare * sizeof(DIM)); // noul vector suport pentru struct Heap 126 | for (int i = 0; i < nKeys; i++) 127 | new_strHeap[i] = strHeap[i]; // copiere chei din structura curenta (incarcata la max) pe noua structura Heao 128 | // cheile se pastreaza pe aceleasi locatii pe noua structura 129 | 130 | free(strHeap); // eliberare mem heap pentru struct Heap curenta 131 | strHeap = new_strHeap; // comutare variabila accces vector suport pe noul vector suport struct Heap 132 | } 133 | 134 | inserare_cheie_heap(strHeap, &nKeys, cheie); 135 | 136 | fscanf(f, "%d", &cheie); 137 | } 138 | 139 | printf("\n Structura Heap initiala: "); 140 | for (int i = 0; i < nKeys; i++) 141 | printf(" %d ", strHeap[i]); 142 | 143 | inserare_cheie_heap(strHeap, &nKeys, 26); 144 | 145 | printf("\n\n Structura Heap dupa inserare cheie 26: "); 146 | for (int i = 0; i < nKeys; i++) 147 | printf(" %d ", strHeap[i]); 148 | printf("\n"); 149 | 150 | cheie = stergere_cheie_heap(strHeap, &nKeys); 151 | 152 | printf("\n\n Structura Heap dupa stergere cheie din radacina: "); 153 | for (int i = 0; i < nKeys; i++) 154 | printf(" %d ", strHeap[i]); 155 | printf("\n"); 156 | 157 | 158 | printf("Stergere chei din structura Heap: "); 159 | while (nKeys > 0) 160 | { 161 | printf(" %d ", stergere_cheie_heap(strHeap, &nKeys)); 162 | } 163 | printf("\n\n"); 164 | 165 | // Dezalocare vector suport 166 | free(strHeap); 167 | 168 | printf("\n\n Structura Heap dupa dezalocare structura Heap: "); 169 | for (int i = 0; i < nKeys; i++) 170 | printf(" %d ", strHeap[i]); 171 | printf("\n"); 172 | 173 | fclose(f); 174 | return 0; 175 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/10_Struct_MaxHeap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define CAPACITATE_STOCARE_STRUCT_HEAP 6 5 | 6 | unsigned short int *agregare_struct_heap(unsigned short int *struct_heap_1, unsigned short int size_struct_heap1, 7 | unsigned short int* struct_heap_2, unsigned short int size_struct_heap2, 8 | unsigned short int* struct_heap_agregata, unsigned short int *nr_noduri, 9 | unsigned short int * capacitate_stocare_agregat, 10 | unsigned short int cheie) 11 | { 12 | unsigned short int k = 0; // offset curent in structura agregata 13 | struct_heap_agregata[k++] = cheie; // inserare cheie in structura agreagata 14 | *nr_noduri += 1; 15 | 16 | // structura heap 1 (stanga) trebuie sa fie mai mare decat cealalta pentru a obtine o structura heap agregata 17 | // corecta din punct de vedere al asezarii nodurilor in arborele Heap 18 | if (size_struct_heap1 < size_struct_heap2) 19 | { 20 | // structura heap 2 este mai mare 21 | // se interschimba pointerii de acces la structuri (vector) si dimensiunile celor 2 vectori 22 | 23 | unsigned short int* paux = struct_heap_1; 24 | struct_heap_1 = struct_heap_2; 25 | struct_heap_2 = paux; 26 | 27 | unsigned short int saux = size_struct_heap1; 28 | size_struct_heap1 = size_struct_heap2; 29 | size_struct_heap2 = saux; 30 | } 31 | 32 | unsigned flag = 1; 33 | unsigned short int nr_h = 1; // numar de noduri de pe nivel curent h 34 | unsigned short int i = 0; // offset de traversare structura heap struct_heap_1 35 | unsigned short int j = 0; // offset de traversare structura heap struct_heap_2 36 | while (flag) 37 | { 38 | unsigned short int l = i; // nr elemente preluate din struct_heap_1 si struct_heap_2 in interatiile anterioare 39 | for (i; i < nr_h + l && i < size_struct_heap1; i++) 40 | { 41 | struct_heap_agregata[k++] = struct_heap_1[i]; 42 | *nr_noduri += 1; 43 | // validare nr_noduri mai mic decat capacitate 44 | if (*nr_noduri == *capacitate_stocare_agregat) 45 | { 46 | // nu mai exista pozitii disponibile in structura agregata 47 | // realocare structura agregata pe +CAPACITATE_STOCARE_STRUCT_HEAP elemente 48 | *capacitate_stocare_agregat = *capacitate_stocare_agregat + CAPACITATE_STOCARE_STRUCT_HEAP; 49 | unsigned short int* new_struct_heap = malloc((*capacitate_stocare_agregat) * sizeof(unsigned short int)); 50 | for (unsigned short int idx = 0; idx < *nr_noduri; idx++) 51 | { 52 | // mutare elemente de pe structura curenta pe noua structra 53 | new_struct_heap[idx] = struct_heap_agregata[idx]; 54 | } 55 | // dezalocare structura cu capacitate la maxim 56 | free(struct_heap_agregata); 57 | // comutare pe noua structura 58 | struct_heap_agregata = new_struct_heap; 59 | } 60 | } 61 | l = j; 62 | for (j; j < nr_h + l && j < size_struct_heap2; j++) 63 | { 64 | struct_heap_agregata[k++] = struct_heap_2[j]; 65 | *nr_noduri += 1; 66 | // validare nr_noduri mai mic decat capacitate 67 | if (*nr_noduri == *capacitate_stocare_agregat) 68 | { 69 | // nu mai exista pozitii disponibile in structura agregata 70 | // realocare structura agregata pe +CAPACITATE_STOCARE_STRUCT_HEAP elemente 71 | *capacitate_stocare_agregat = *capacitate_stocare_agregat + CAPACITATE_STOCARE_STRUCT_HEAP; 72 | unsigned short int* new_struct_heap = malloc((*capacitate_stocare_agregat) * sizeof(unsigned short int)); 73 | for (unsigned short int idx = 0; idx < *nr_noduri; idx++) 74 | { 75 | // mutare elemente de pe structura curenta pe noua structra 76 | new_struct_heap[idx] = struct_heap_agregata[idx]; 77 | } 78 | // dezalocare structura cu capacitate la maxim 79 | free(struct_heap_agregata); 80 | // comutare pe noua structura 81 | struct_heap_agregata = new_struct_heap; 82 | } 83 | } 84 | if (i >= size_struct_heap1 && j >= size_struct_heap2) 85 | flag = 0; 86 | 87 | nr_h = nr_h * 2; // determinare numar de chei de pe nivel urmator (mai jos pe arborele Heap) 88 | } 89 | 90 | return struct_heap_agregata; 91 | } 92 | 93 | int main() 94 | { 95 | unsigned short int *struct_heap_agregata = NULL; // structura max-heap cu elemente rezultate din agregare structuri heap 96 | unsigned short int struct_heap_1[] = {32, 12, 24, 7, 9, 17}; 97 | unsigned short int struct_heap_2[] = {8, 2, 3}; 98 | unsigned short int capacitate_stocare = CAPACITATE_STOCARE_STRUCT_HEAP; 99 | unsigned short int nr_noduri_struct_heap = 0; 100 | 101 | struct_heap_agregata = malloc(capacitate_stocare * sizeof(unsigned short int)); // alocare structura heap agregata la capacitate max 102 | 103 | // 1. ma asigur ca diferenta de inaltime dintre cele doua structuri este de maxim 1 nivel!!!! 104 | // 2. ma asigur ca ultimul nivel din structura heap 1 este complet ocupat cu noduri daca cele doua structuri Heap 105 | // au aceeasi inaltime. Scopul este ca structura Heap agregata sa fie corecta din punct de vedere al asezarii nodurilor: 106 | // arbore bina complet 107 | struct_heap_agregata = agregare_struct_heap(struct_heap_2, sizeof(struct_heap_2) / sizeof(unsigned short int), 108 | struct_heap_1, sizeof(struct_heap_1) / sizeof(unsigned short int), 109 | struct_heap_agregata, &nr_noduri_struct_heap, &capacitate_stocare, 110 | 23); 111 | 112 | printf("Structura agregata cu nr chei = %hu si capacitate de stocare = %hu este: ", 113 | nr_noduri_struct_heap, capacitate_stocare); 114 | for (unsigned short int i = 0; i < nr_noduri_struct_heap; i++) 115 | printf("%hu ", struct_heap_agregata[i]); 116 | printf("\n\n"); 117 | 118 | // se apeleaza functia de cautare a locului corect in arborele Heap pentru nodul radacina (cheia inserata 23!!!) 119 | // vezi suport curs: operatia de stergere!!! 120 | 121 | return 0; 122 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1076Sol/Grupa1076Proj/05_DoubleList.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define CARD_NUMBER_LENGTH 16 8 | #define EXPIRING_DATE_FORMAT_LENGTH 5 // MM/YY 9 | 10 | struct BankCard 11 | { 12 | char* holder; 13 | char card_no[CARD_NUMBER_LENGTH + 1]; 14 | float balance; 15 | char exp_date[EXPIRING_DATE_FORMAT_LENGTH + 1]; 16 | char* currency; 17 | }; 18 | 19 | typedef struct BankCard BankCard; 20 | 21 | struct NodeD 22 | { 23 | BankCard data; 24 | struct NodeD* next, * prev; // mem address of the next and previous items (nodes) in the chain 25 | }; 26 | 27 | typedef struct NodeD NodeD; 28 | 29 | struct DoubleList 30 | { 31 | NodeD* head, * tail; 32 | }; 33 | 34 | typedef struct DoubleList DoubleList; 35 | 36 | // insert a node into a double list (at the end) 37 | DoubleList insert_node(DoubleList list, BankCard bc) 38 | { 39 | NodeD* new_node = malloc(sizeof(NodeD)); 40 | new_node->data = bc; 41 | new_node->next = NULL; 42 | new_node->prev = list.tail; 43 | 44 | if (list.head == NULL) 45 | { 46 | // the list is empty: list.head == list.tail == NULL 47 | list.head = new_node; 48 | list.tail = new_node; 49 | } 50 | else 51 | { 52 | // there is one node at least in double list 53 | list.tail->next = new_node; // the tail becomes the node before the last one (new_node) 54 | list.tail = new_node; // update the tail of the lista after adding the new_node at the end 55 | } 56 | 57 | return list; 58 | } 59 | 60 | void parse_list(DoubleList list) 61 | { 62 | NodeD* temp = list.head; 63 | printf("Double list head-to-tail:\n"); 64 | while (temp != NULL) 65 | { 66 | printf("%s %s\n", temp->data.card_no, temp->data.holder); 67 | temp = temp->next; 68 | } 69 | 70 | temp = list.tail; 71 | printf("\nDouble list tail-to-head;\n"); 72 | while (temp != NULL) 73 | { 74 | printf("%s %s\n", temp->data.card_no, temp->data.holder); 75 | temp = temp->prev; 76 | } 77 | } 78 | 79 | // delete all node having the same holder's name 80 | DoubleList delete_nodes_holder(DoubleList list, char* holder_name) 81 | { 82 | 83 | } 84 | 85 | // swap 2 nodes in the double list by changing the prev and next pointers 86 | 87 | DoubleList delete_node_middle(DoubleList list, char* card_number) 88 | { 89 | if (list.head != NULL) 90 | { 91 | // there is one node at least in my double list 92 | NodeD* temp = list.head; 93 | 94 | while (temp!= NULL && strcmp(temp->data.card_no, card_number) != 0) 95 | { 96 | // the temp is not the node to be deleted 97 | temp = temp->next; 98 | } 99 | 100 | if (temp != NULL) 101 | { 102 | // the node to be deleted has been identified as temp 103 | // there is one single node with card_number in the list (unique values for card_number) 104 | if (temp == list.head) 105 | { 106 | // head will be deleted 107 | list.head = list.head->next; 108 | if (list.head != NULL) 109 | { 110 | list.head->prev = NULL; // the second node becomes the new head of the double list 111 | } 112 | else 113 | { 114 | list.tail = NULL; // double list becomes an empty list 115 | } 116 | } 117 | else 118 | { 119 | if (temp == list.tail) 120 | { 121 | list.tail = list.tail->prev; // update of tail with previous node 122 | list.tail->next = NULL; // make the previous node as being the new tail of the double list 123 | } 124 | else 125 | { 126 | // temp is not neither head or tail 127 | (temp->prev)->next = temp->next; // (temp->prev) is the node right before the temp 128 | (temp->next)->prev = temp->prev; // (temp->next) is the node right after the temp 129 | } 130 | } 131 | 132 | // deallocate the node temp 133 | free(temp->data.holder); // deallocate holder within the card structure 134 | free(temp->data.currency); // deallocate currency within the card structure 135 | free(temp); // deallocate the NODE temp 136 | } 137 | } 138 | 139 | return list; 140 | } 141 | 142 | 143 | int main() 144 | { 145 | FILE* f = fopen("CardData.txt", "r"); 146 | DoubleList d_list; 147 | d_list.head = NULL; 148 | d_list.tail = NULL; 149 | 150 | unsigned char buffer[200]; 151 | while (fgets(buffer, sizeof(buffer), f)) 152 | { 153 | BankCard card; 154 | char seps[] = ",\n"; 155 | char* token = strtok(buffer, seps); // splitting started from the beginning of buffer array 156 | strcpy(card.card_no, token); 157 | 158 | token = strtok(NULL, seps); // continue the splitting of buffer from the current point 159 | strcpy(card.exp_date, token); 160 | 161 | token = strtok(NULL, seps); // continue the splitting of buffer from the current point 162 | card.holder = malloc(strlen(token) + 1); 163 | strcpy(card.holder, token); 164 | 165 | token = strtok(NULL, seps); // continue the splitting of buffer from the current point 166 | card.currency = malloc(strlen(token) + 1); 167 | strcpy(card.currency, token); 168 | 169 | token = strtok(NULL, seps); // continue the splitting of buffer from the current point 170 | card.balance = (float)atof(token); 171 | 172 | // insert card data into a simple list 173 | d_list = insert_node(d_list, card); 174 | } 175 | 176 | fclose(f); 177 | 178 | printf("Duble list after creation:\n"); 179 | parse_list(d_list); 180 | 181 | d_list = delete_node_middle(d_list, "6523667711220094"); 182 | printf("\nDouble list after deletion of one node:\n"); 183 | parse_list(d_list); 184 | 185 | // deallocate the entire list by calling the one single node deletion 186 | // for the card number taken from the head everytime 187 | while (d_list.head != NULL) 188 | { 189 | d_list = delete_node_middle(d_list, d_list.head->data.card_no); 190 | } 191 | printf("\nDouble list after deallocation:\n"); 192 | parse_list(d_list); 193 | 194 | 195 | // insert a node in the middle of the list (define criteria!) 196 | // delete a node at the begining and the end of the list 197 | 198 | return 0; 199 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1062Sol/Grupa1062Proj/05_ListeDuble.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define DIM_CARD_BANCAR 16 9 | #define DIM_DATA_EXPIRARE 7 10 | #define DIM_MONEDA 3 11 | 12 | 13 | struct CardBancar 14 | { 15 | char nr_card[DIM_CARD_BANCAR + 1]; // +1 pentru terminator string; 20 bytes (17 + 3 padding) 16 | char* titular; // 4 bytes 17 | char data_expirare[DIM_DATA_EXPIRARE + 1]; // +1 pentru terminator string; 12 bytes (9 + 3 padding) 18 | float sold; // 4 bytes 19 | char moneda[DIM_MONEDA + 1]; // cod moneda; 4 bytes (no padding) 20 | }; 21 | 22 | typedef struct CardBancar CardBancar; 23 | 24 | struct NodD 25 | { 26 | CardBancar cb; 27 | struct NodD* next, *prev; 28 | }; 29 | 30 | typedef struct NodD NodD; 31 | 32 | struct ListaDubla 33 | { 34 | NodD* prim, * ultim; 35 | }; 36 | 37 | typedef struct ListaDubla ListaDubla; 38 | 39 | // inserare nod la interior pe criteriu definit (dupa nod cu nr_card specificat) 40 | ListaDubla inserare_nod_interior(ListaDubla lista, CardBancar data, char* numar_card) 41 | { 42 | if (lista.prim == NULL) 43 | { 44 | // lista nu contine nici un nod 45 | NodD* nou = malloc(sizeof(NodD)); 46 | nou->cb = data; 47 | nou->next = NULL; 48 | nou->prev = NULL; 49 | lista.prim = nou; 50 | lista.ultim = nou; 51 | } 52 | else 53 | { 54 | // cel putin 1 nod in lista 55 | // cautare nod cu numar_card 56 | NodD* temp = lista.prim; 57 | while (temp != NULL) 58 | { 59 | if (strcmp(temp->cb.nr_card, numar_card) == 0) 60 | { 61 | // nodul cu nr card cautat a fost identificat 62 | // nou se insereaza dupa temp 63 | NodD* nou = malloc(sizeof(NodD)); 64 | nou->cb = data; 65 | nou->prev = temp; 66 | nou->next = temp->next; 67 | NodD* succesor_temp = temp->next; 68 | temp->next = nou; 69 | 70 | if (nou->next == NULL) 71 | { 72 | // nou se insereaza la sfarsitul listei duble 73 | lista.ultim = nou; 74 | } 75 | else 76 | { 77 | // exista succesor pt temp inainte de atasarea lui nou la lista dubla 78 | succesor_temp->prev = nou; 79 | } 80 | temp = NULL; // fortare iesire din while 81 | } 82 | else 83 | temp = temp->next; 84 | } 85 | } 86 | 87 | return lista; 88 | } 89 | 90 | void traversare_listadubla(ListaDubla lista) 91 | { 92 | NodD* temp = lista.prim; 93 | printf("Lista dubla traversare prim->ultim:\n"); 94 | while (temp) 95 | { 96 | printf("%s %s\n", temp->cb.nr_card, temp->cb.titular); 97 | temp = temp->next; 98 | } 99 | 100 | temp = lista.ultim; 101 | printf("Lista dubla traversare ultim->prim:\n"); 102 | while (temp) 103 | { 104 | printf("%s %s\n", temp->cb.nr_card, temp->cb.titular); 105 | temp = temp->prev; 106 | } 107 | } 108 | 109 | ListaDubla stergere_inceput(ListaDubla lista) 110 | { 111 | if (lista.prim != NULL) 112 | { 113 | NodD* temp = lista.prim; 114 | lista.prim = lista.prim->next; 115 | 116 | if (lista.prim == NULL) 117 | { 118 | // lista dubla devine empty 119 | lista.ultim = NULL; 120 | } 121 | else 122 | { 123 | lista.prim->prev = NULL; 124 | } 125 | 126 | free(temp->cb.titular); // dezalocare string titular card bancar 127 | free(temp); // dezalocare nod lista dubla 128 | } 129 | 130 | return lista; 131 | } 132 | 133 | // functie salvare intr-un vector de string-uri 134 | // a nr carduri stocate in lista dubla 135 | 136 | 137 | int main() 138 | { 139 | // preluare date din fisier pentru carduri bancare 140 | FILE* f = NULL; 141 | f = fopen("CarduriBancare.txt", "r"); 142 | 143 | CardBancar card; 144 | ListaDubla listaD; // variabila cu pointeri de acces la capetele listei duble 145 | listaD.prim = NULL; // nu exista primul nod (lista empty) 146 | listaD.ultim = NULL; // nu exista ultimul nod (lista empty) 147 | 148 | char buffer[150]; 149 | char sep[] = ";\n"; 150 | 151 | fgets(buffer, sizeof(buffer), f); 152 | 153 | while (!feof(f)) 154 | { 155 | char* token = NULL; 156 | token = strtok(buffer, sep); 157 | strcpy(card.nr_card, token); 158 | 159 | token = strtok(NULL, sep); 160 | card.titular = malloc(strlen(token) + 1); 161 | strcpy(card.titular, token); 162 | 163 | token = strtok(NULL, sep); 164 | strcpy(card.data_expirare, token); 165 | 166 | token = strtok(NULL, sep); 167 | card.sold = (float)atof(token); 168 | 169 | token = strtok(NULL, sep); 170 | strcpy(card.moneda, token); 171 | 172 | // apel de functie pentru inserare nod in lista simpla 173 | if (listaD.prim == NULL) 174 | { 175 | // lista este empty 176 | listaD = inserare_nod_interior(listaD, card, ""); 177 | } 178 | else 179 | { 180 | listaD = inserare_nod_interior(listaD, card, listaD.prim->cb.nr_card); // listaD.prim->cb.nr_card exista sigur in lista 181 | } 182 | 183 | // verificare prezenta card in lista dubla 184 | NodD* temp = listaD.prim; 185 | unsigned char flag = 0; // card.nr_card nu este prezent in lista dubla 186 | while ((temp != NULL) && (flag == 0)) 187 | { 188 | // cautare prezenta card.nr_card in lista dubla dupa apel functie inserare nod 189 | if (strcmp(temp->cb.nr_card, card.nr_card) == 0) 190 | { 191 | flag = 1; // card.nr_card este gasit in lista dubla 192 | } 193 | temp = temp->next; 194 | } 195 | if (flag == 0) // card nu a fost inserat in lista dubla 196 | { 197 | // card.nr_card nu a fost gasit in lista dubla, deci nu a avut loc inserarea 198 | free(card.titular); 199 | } 200 | 201 | // incercare preluare linie urmatoare (daca exista) 202 | fgets(buffer, sizeof(buffer), f); 203 | } 204 | fclose(f); 205 | 206 | printf("Lista dubla dupa creare:\n"); 207 | traversare_listadubla(listaD); 208 | 209 | listaD = stergere_inceput(listaD); 210 | printf("\n\nLista dubla dupa stergerea primului nod:\n"); 211 | traversare_listadubla(listaD); 212 | 213 | while (listaD.prim != NULL) 214 | { 215 | // exista cel putin 1 nod in lista dubla 216 | listaD = stergere_inceput(listaD); 217 | } 218 | printf("\n\nLista dubla dupa dezalocare:\n"); 219 | traversare_listadubla(listaD); 220 | 221 | // stergere nod din lista dubla (inceput, sfarsit) 222 | 223 | // stergere noduri cu acelasi titular in lista dubla 224 | // Implementare QuickSort 225 | } -------------------------------------------------------------------------------- /2024-2025/Grupa1059Sol/Grupa1059Proj/14_Graf.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | typedef struct Nod Nod; 6 | typedef struct NodLS NodLS; 7 | typedef struct NodLP NodLP; 8 | 9 | // structura nod lista principala 10 | struct NodLS; 11 | struct NodLP { 12 | unsigned int idVarf; 13 | NodLS* primListaVecini; 14 | NodLP* next; 15 | }; 16 | 17 | // structura nod lista secundara 18 | struct NodLS { 19 | unsigned int idNodAdiacent; 20 | NodLS* next; 21 | }; 22 | 23 | // structura nod stiva 24 | struct Nod { 25 | unsigned int idVarf; 26 | Nod* next; 27 | }; 28 | 29 | // inserare nod in lista secundara 30 | NodLS* inserareNodLS(NodLS* pLS, unsigned int id) { 31 | NodLS* nou = (NodLS*)malloc(sizeof(NodLS)); 32 | nou->idNodAdiacent = id; 33 | nou->next = 0; 34 | 35 | if (!pLS) { // LS nu contine nici un nod 36 | return nou; 37 | } 38 | else { 39 | // parsare LS pana la ultimul nod 40 | NodLS* tmp = pLS; 41 | while (tmp->next) 42 | tmp = tmp->next; 43 | 44 | tmp->next = nou; 45 | } 46 | 47 | return pLS; 48 | } 49 | 50 | // inserare nod in lista principala 51 | NodLP* inserareNodLP(NodLP* pLP, unsigned int id, NodLS* pLstVecini) { 52 | NodLP* nou = (NodLP*)malloc(sizeof(NodLP)); 53 | nou->idVarf = id; 54 | nou->primListaVecini = pLstVecini; 55 | nou->next = 0; 56 | 57 | if (!pLP) { // LP nu contine nici un nod 58 | return nou; 59 | } 60 | else { 61 | // parsare LP pana la ultimul nod 62 | NodLP* tmp = pLP; 63 | while (tmp->next) 64 | tmp = tmp->next; 65 | 66 | tmp->next = nou; 67 | } 68 | 69 | return pLP; 70 | } 71 | 72 | // cauta nod (varf graf) in lista principala 73 | NodLP* cautaNodLP(NodLP* pLP, unsigned int idCautat) { 74 | NodLP* tmp = pLP; 75 | while (tmp) { 76 | if (tmp->idVarf == idCautat) 77 | return tmp; // adresa nod in LP cu idCautat 78 | 79 | tmp = tmp->next; 80 | } 81 | 82 | return tmp; // NULL; nu exista nod in LP cu idCautat 83 | } 84 | 85 | Nod* push(Nod* stack, unsigned int varf) 86 | { 87 | Nod* nou = malloc(sizeof(Nod)); 88 | nou->idVarf = varf; 89 | nou->next = stack; 90 | 91 | return nou; 92 | } 93 | 94 | Nod* pop(Nod* stack, unsigned int* varf) 95 | { 96 | if (stack) 97 | { 98 | *varf = stack->idVarf; 99 | Nod* tmp = stack; 100 | stack = stack->next; 101 | 102 | free(tmp); 103 | } 104 | 105 | return stack; 106 | } 107 | 108 | // traversare DF a grafului 109 | unsigned int* DF(NodLP* pLP, unsigned int start, unsigned int nrVarfuri) { 110 | unsigned int* flags, * output, k = 0; 111 | Nod* stack = 0; 112 | 113 | // alocare vector de flaguri 114 | flags = (unsigned int*)malloc(nrVarfuri * sizeof(unsigned int)); 115 | // initializare vector flaguri 116 | for (unsigned int i = 0; i < nrVarfuri; i++) 117 | flags[i] = 0; 118 | 119 | // alocare vector de iesire 120 | output = (unsigned int*)malloc(nrVarfuri * sizeof(unsigned int)); 121 | 122 | // push varf de start 123 | stack = push(stack, start); 124 | flags[start - 1] = 1; 125 | 126 | while (stack) { 127 | unsigned int varf; 128 | // extragere nod graf din varful stivei 129 | stack = pop(stack, &varf); 130 | 131 | // salvare in banda de iesire a varfului extras in vederea prelucrarii 132 | output[k] = varf; 133 | k = k + 1; 134 | 135 | // TO DO: stabilire vecini pentru varf 136 | // cauta varf in LP 137 | NodLP* tmpLP = cautaNodLP(pLP, varf); 138 | NodLS* tmpLS = tmpLP->primListaVecini; // acces lista de varfuri adiacente 139 | while (tmpLS) 140 | { 141 | 142 | // TO DO: push pentru vecinii cu flags nul 143 | int vecin = tmpLS->idNodAdiacent; 144 | if (flags[vecin - 1] == 0) 145 | { 146 | // vecin nu a fost salvat anterior pe stack 147 | stack = push(stack, vecin); 148 | // TO DO: comutare flags pentru vecinii salvati pe stiva 149 | flags[vecin - 1] = 1; // comutare flag 150 | } 151 | 152 | tmpLS = tmpLS->next; 153 | } 154 | 155 | } 156 | 157 | return output; 158 | } 159 | 160 | // TO DO: functia traversare BF 161 | 162 | // TO DO: functia put pentru coada 163 | 164 | // TO DO: functia get pentru coada 165 | 166 | void main() { 167 | FILE* f; 168 | f = fopen("Graf.txt", "r"); 169 | 170 | char buffer[128]; 171 | fgets(buffer, sizeof(buffer), f); 172 | 173 | NodLP* pListaAdiacenta = 0; 174 | unsigned int nrVarfuri = 0; 175 | 176 | sscanf(buffer, "%d", &nrVarfuri); // preluare nr varfuri de pe prima linie din fisier 177 | for (unsigned int i = 1; i <= nrVarfuri; i++) // creare noduri LP 178 | pListaAdiacenta = inserareNodLP(pListaAdiacenta, i, NULL); 179 | 180 | 181 | while (fgets(buffer, sizeof(buffer), f)) { 182 | unsigned int src, dst; 183 | sscanf(buffer, "%d %d", &src, &dst); 184 | 185 | NodLP* tmpLP = cautaNodLP(pListaAdiacenta, src); 186 | 187 | if (tmpLP) { 188 | // nodul cu idVarf == src 189 | tmpLP->primListaVecini = inserareNodLS(tmpLP->primListaVecini, dst); 190 | 191 | // pentru a insera si muchia inversa (graful devine neorientat) 192 | // cauta nod in LP cu varf sursa nodul 2 preluat din fisier 193 | tmpLP = cautaNodLP(pListaAdiacenta, dst); 194 | tmpLP->primListaVecini = inserareNodLS(tmpLP->primListaVecini, src); 195 | } 196 | else { 197 | // nu exista nodul cautat in LP 198 | printf("\nNodul cautat cu id %d nu exista.\n", src); 199 | } 200 | } 201 | 202 | // parsare lista de adiacenta 203 | NodLP* tmpLP = pListaAdiacenta; 204 | while (tmpLP) { 205 | 206 | printf("\nVarf %d cu vecinii: ", tmpLP->idVarf); 207 | 208 | NodLS* tmpLS = tmpLP->primListaVecini; 209 | while (tmpLS) { 210 | printf(" %d ", tmpLS->idNodAdiacent); 211 | 212 | tmpLS = tmpLS->next; 213 | } 214 | 215 | tmpLP = tmpLP->next; 216 | } 217 | unsigned int* vector_traversare = DF(pListaAdiacenta, 1, nrVarfuri); 218 | 219 | printf("\n\nTraversare DF graf:"); 220 | for (unsigned int i = 0; i < nrVarfuri; i++) 221 | printf(" %u", vector_traversare[i]); 222 | 223 | // dezalocare vector_traversare 224 | free(vector_traversare); 225 | 226 | 227 | //vector_traversare = BF(pListaAdiacenta, 1, nrVarfuri); 228 | //printf("\n\nTraversare BF graf:"); 229 | //for (unsigned int i = 0; i < nrVarfuri; i++) 230 | // printf(" %u", vector_traversare[i]); 231 | //// dezalocare vector_traversare 232 | //free(vector_traversare); 233 | 234 | printf("\n\n"); 235 | fclose(f); 236 | } 237 | 238 | 239 | -------------------------------------------------------------------------------- /2024-2025/Grupa1055Sol/Grupa1055Proj/14_Graf.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | 6 | typedef struct Nod Nod; 7 | typedef struct NodLS NodLS; 8 | typedef struct NodLP NodLP; 9 | 10 | // structura nod lista principala 11 | struct NodLS; 12 | struct NodLP { 13 | unsigned int idVarf; 14 | NodLS* primListaVecini; 15 | NodLP* next; 16 | }; 17 | 18 | // structura nod lista secundara 19 | struct NodLS { 20 | unsigned int idNodAdiacent; 21 | NodLS* next; 22 | }; 23 | 24 | // structura nod stiva 25 | struct Nod { 26 | unsigned int idVarf; 27 | Nod* next; 28 | }; 29 | 30 | // inserare nod in lista secundara 31 | NodLS* inserareNodLS(NodLS* pLS, unsigned int id) { 32 | NodLS* nou = (NodLS*)malloc(sizeof(NodLS)); 33 | nou->idNodAdiacent = id; 34 | nou->next = 0; 35 | 36 | if (!pLS) { // LS nu contine nici un nod 37 | return nou; 38 | } 39 | else { 40 | // parsare LS pana la ultimul nod 41 | NodLS* tmp = pLS; 42 | while (tmp->next) 43 | tmp = tmp->next; 44 | 45 | tmp->next = nou; 46 | } 47 | 48 | return pLS; 49 | } 50 | 51 | // inserare nod in lista principala 52 | NodLP* inserareNodLP(NodLP* pLP, unsigned int id, NodLS* pLstVecini) { 53 | NodLP* nou = (NodLP*)malloc(sizeof(NodLP)); 54 | nou->idVarf = id; 55 | nou->primListaVecini = pLstVecini; 56 | nou->next = 0; 57 | 58 | if (!pLP) { // LP nu contine nici un nod 59 | return nou; 60 | } 61 | else { 62 | // parsare LP pana la ultimul nod 63 | NodLP* tmp = pLP; 64 | while (tmp->next) 65 | tmp = tmp->next; 66 | 67 | tmp->next = nou; 68 | } 69 | 70 | return pLP; 71 | } 72 | 73 | // cauta nod (varf graf) in lista principala 74 | NodLP* cautaNodLP(NodLP* pLP, unsigned int idCautat) { 75 | NodLP* tmp = pLP; 76 | while (tmp) { 77 | if (tmp->idVarf == idCautat) 78 | return tmp; // adresa nod in LP cu idCautat 79 | 80 | tmp = tmp->next; 81 | } 82 | 83 | return tmp; // NULL; nu exista nod in LP cu idCautat 84 | } 85 | 86 | Nod* push(Nod* stack, unsigned int varf) 87 | { 88 | Nod* nou = malloc(sizeof(Nod)); 89 | nou->idVarf = varf; 90 | nou->next = stack; 91 | 92 | return nou; 93 | } 94 | 95 | Nod* pop(Nod* stack, unsigned int *varf) 96 | { 97 | if (stack) 98 | { 99 | *varf = stack->idVarf; 100 | Nod* tmp = stack; 101 | stack = stack->next; 102 | 103 | free(tmp); 104 | } 105 | 106 | return stack; 107 | } 108 | 109 | // traversare DF a grafului 110 | unsigned int* DF(NodLP* pLP, unsigned int start, unsigned int nrVarfuri) { 111 | unsigned int* flags, * output, k = 0; 112 | Nod* stack = 0; 113 | 114 | // alocare vector de flaguri 115 | flags = (unsigned int*)malloc(nrVarfuri * sizeof(unsigned int)); 116 | // initializare vector flaguri 117 | for (unsigned int i = 0; i < nrVarfuri; i++) 118 | flags[i] = 0; 119 | 120 | // alocare vector de iesire 121 | output = (unsigned int*)malloc(nrVarfuri * sizeof(unsigned int)); 122 | 123 | // push varf de start 124 | stack = push(stack, start); 125 | flags[start - 1] = 1; 126 | 127 | while (stack) { 128 | unsigned int varf; 129 | // extragere nod graf din varful stivei 130 | stack = pop(stack, &varf); 131 | 132 | // salvare in banda de iesire a varfului extras in vederea prelucrarii 133 | output[k] = varf; 134 | k = k + 1; 135 | 136 | // TO DO: stabilire vecini pentru varf 137 | // cauta varf in LP 138 | NodLP* tmpLP = cautaNodLP(pLP, varf); 139 | NodLS* tmpLS = tmpLP->primListaVecini; // acces lista de varfuri adiacente 140 | while (tmpLS) 141 | { 142 | 143 | // TO DO: push pentru vecinii cu flags nul 144 | int vecin = tmpLS->idNodAdiacent; 145 | if (flags[vecin - 1] == 0) 146 | { 147 | // vecin nu a fost salvat anterior pe stack 148 | stack = push(stack, vecin); 149 | // TO DO: comutare flags pentru vecinii salvati pe stiva 150 | flags[vecin - 1] = 1; // comutare flag 151 | } 152 | 153 | tmpLS = tmpLS->next; 154 | } 155 | 156 | } 157 | 158 | return output; 159 | } 160 | 161 | // TO DO: functia traversare BF 162 | 163 | // TO DO: functia put pentru coada 164 | 165 | // TO DO: functia get pentru coada 166 | 167 | void main() { 168 | FILE* f; 169 | f = fopen("Graf.txt", "r"); 170 | 171 | char buffer[128]; 172 | fgets(buffer, sizeof(buffer), f); 173 | 174 | NodLP* pListaAdiacenta = 0; 175 | unsigned int nrVarfuri = 0; 176 | 177 | sscanf(buffer, "%d", &nrVarfuri); // preluare nr varfuri de pe prima linie din fisier 178 | for (unsigned int i = 1; i <= nrVarfuri; i++) // creare noduri LP 179 | pListaAdiacenta = inserareNodLP(pListaAdiacenta, i, NULL); 180 | 181 | 182 | while (fgets(buffer, sizeof(buffer), f)) { 183 | unsigned int src, dst; 184 | sscanf(buffer, "%d %d", &src, &dst); 185 | 186 | NodLP* tmpLP = cautaNodLP(pListaAdiacenta, src); 187 | 188 | if (tmpLP) { 189 | // nodul cu idVarf == src 190 | tmpLP->primListaVecini = inserareNodLS(tmpLP->primListaVecini, dst); 191 | 192 | // pentru a insera si muchia inversa (graful devine neorientat) 193 | // cauta nod in LP cu varf sursa nodul 2 preluat din fisier 194 | tmpLP = cautaNodLP(pListaAdiacenta, dst); 195 | tmpLP->primListaVecini = inserareNodLS(tmpLP->primListaVecini, src); 196 | } 197 | else { 198 | // nu exista nodul cautat in LP 199 | printf("\nNodul cautat cu id %d nu exista.\n", src); 200 | } 201 | } 202 | 203 | // parsare lista de adiacenta 204 | NodLP* tmpLP = pListaAdiacenta; 205 | while (tmpLP) { 206 | 207 | printf("\nVarf %d cu vecinii: ", tmpLP->idVarf); 208 | 209 | NodLS* tmpLS = tmpLP->primListaVecini; 210 | while (tmpLS) { 211 | printf(" %d ", tmpLS->idNodAdiacent); 212 | 213 | tmpLS = tmpLS->next; 214 | } 215 | 216 | tmpLP = tmpLP->next; 217 | } 218 | unsigned int* vector_traversare = DF(pListaAdiacenta, 1, nrVarfuri); 219 | 220 | printf("\n\nTraversare DF graf:"); 221 | for (unsigned int i = 0; i < nrVarfuri; i++) 222 | printf(" %u", vector_traversare[i]); 223 | 224 | // dezalocare vector_traversare 225 | free(vector_traversare); 226 | 227 | 228 | //vector_traversare = BF(pListaAdiacenta, 1, nrVarfuri); 229 | //printf("\n\nTraversare BF graf:"); 230 | //for (unsigned int i = 0; i < nrVarfuri; i++) 231 | // printf(" %u", vector_traversare[i]); 232 | //// dezalocare vector_traversare 233 | //free(vector_traversare); 234 | 235 | printf("\n\n"); 236 | fclose(f); 237 | } 238 | 239 | 240 | -------------------------------------------------------------------------------- /2024-2025/Grupa1058Sol/Grupa1058Proj/14_Graf_lst.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | 6 | typedef struct Nod Nod; 7 | typedef struct NodLS NodLS; 8 | typedef struct NodLP NodLP; 9 | 10 | // structura nod lista principala 11 | struct NodLS; 12 | struct NodLP { 13 | unsigned int idVarf; 14 | NodLS* primListaVecini; 15 | NodLP* next; 16 | }; 17 | 18 | // structura nod lista secundara 19 | struct NodLS { 20 | unsigned int idNodAdiacent; 21 | NodLS* next; 22 | }; 23 | 24 | // structura nod stiva 25 | struct Nod { 26 | unsigned int idVarf; 27 | Nod* next; 28 | }; 29 | 30 | // inserare nod in lista secundara 31 | NodLS* inserareNodLS(NodLS* pLS, unsigned int id) { 32 | NodLS* nou = (NodLS*)malloc(sizeof(NodLS)); 33 | nou->idNodAdiacent = id; 34 | nou->next = 0; 35 | 36 | if (!pLS) { // LS nu contine nici un nod 37 | return nou; 38 | } 39 | else { 40 | // parsare LS pana la ultimul nod 41 | NodLS* tmp = pLS; 42 | while (tmp->next) 43 | tmp = tmp->next; 44 | 45 | tmp->next = nou; 46 | } 47 | 48 | return pLS; 49 | } 50 | 51 | // inserare nod in lista principala 52 | NodLP* inserareNodLP(NodLP* pLP, unsigned int id, NodLS* pLstVecini) { 53 | NodLP* nou = (NodLP*)malloc(sizeof(NodLP)); 54 | nou->idVarf = id; 55 | nou->primListaVecini = pLstVecini; 56 | nou->next = 0; 57 | 58 | if (!pLP) { // LP nu contine nici un nod 59 | return nou; 60 | } 61 | else { 62 | // parsare LP pana la ultimul nod 63 | NodLP* tmp = pLP; 64 | while (tmp->next) 65 | tmp = tmp->next; 66 | 67 | tmp->next = nou; 68 | } 69 | 70 | return pLP; 71 | } 72 | 73 | // cauta nod (varf graf) in lista principala 74 | NodLP* cautaNodLP(NodLP* pLP, unsigned int idCautat) { 75 | NodLP* tmp = pLP; 76 | while (tmp) { 77 | if (tmp->idVarf == idCautat) 78 | return tmp; // adresa nod in LP cu idCautat 79 | 80 | tmp = tmp->next; 81 | } 82 | 83 | return tmp; // NULL; nu exista nod in LP cu idCautat 84 | } 85 | 86 | Nod* push(Nod* stack, unsigned int varf) 87 | { 88 | Nod* nou = malloc(sizeof(Nod)); 89 | nou->idVarf = varf; 90 | nou->next = stack; 91 | 92 | return nou; 93 | } 94 | 95 | Nod* pop(Nod* stack, unsigned int* varf) 96 | { 97 | if (stack) 98 | { 99 | *varf = stack->idVarf; 100 | Nod* tmp = stack; 101 | stack = stack->next; 102 | 103 | free(tmp); 104 | } 105 | 106 | return stack; 107 | } 108 | 109 | // traversare DF a grafului 110 | unsigned int* DF(NodLP* pLP, unsigned int start, unsigned int nrVarfuri) { 111 | unsigned int* flags, * output, k = 0; 112 | Nod* stack = 0; 113 | 114 | // alocare vector de flaguri 115 | flags = (unsigned int*)malloc(nrVarfuri * sizeof(unsigned int)); 116 | // initializare vector flaguri 117 | for (unsigned int i = 0; i < nrVarfuri; i++) 118 | flags[i] = 0; 119 | 120 | // alocare vector de iesire 121 | output = (unsigned int*)malloc(nrVarfuri * sizeof(unsigned int)); 122 | 123 | // push varf de start 124 | stack = push(stack, start); 125 | flags[start - 1] = 1; 126 | 127 | while (stack) { 128 | unsigned int varf; 129 | // extragere nod graf din varful stivei 130 | stack = pop(stack, &varf); 131 | 132 | // salvare in banda de iesire a varfului extras in vederea prelucrarii 133 | output[k] = varf; 134 | k = k + 1; 135 | 136 | // TO DO: stabilire vecini pentru varf 137 | // cauta varf in LP 138 | NodLP* tmpLP = cautaNodLP(pLP, varf); 139 | NodLS* tmpLS = tmpLP->primListaVecini; // acces lista de varfuri adiacente 140 | while (tmpLS) 141 | { 142 | 143 | // TO DO: push pentru vecinii cu flags nul 144 | int vecin = tmpLS->idNodAdiacent; 145 | if (flags[vecin - 1] == 0) 146 | { 147 | // vecin nu a fost salvat anterior pe stack 148 | stack = push(stack, vecin); 149 | // TO DO: comutare flags pentru vecinii salvati pe stiva 150 | flags[vecin - 1] = 1; // comutare flag 151 | } 152 | 153 | tmpLS = tmpLS->next; 154 | } 155 | 156 | } 157 | 158 | return output; 159 | } 160 | 161 | // TO DO: functia traversare BF 162 | 163 | // TO DO: functia put pentru coada 164 | 165 | // TO DO: functia get pentru coada 166 | 167 | void main() { 168 | FILE* f; 169 | f = fopen("Graf.txt", "r"); 170 | 171 | char buffer[128]; 172 | fgets(buffer, sizeof(buffer), f); 173 | 174 | NodLP* pListaAdiacenta = 0; 175 | unsigned int nrVarfuri = 0; 176 | 177 | sscanf(buffer, "%d", &nrVarfuri); // preluare nr varfuri de pe prima linie din fisier 178 | for (unsigned int i = 1; i <= nrVarfuri; i++) // creare noduri LP 179 | pListaAdiacenta = inserareNodLP(pListaAdiacenta, i, NULL); 180 | 181 | 182 | while (fgets(buffer, sizeof(buffer), f)) { 183 | unsigned int src, dst; 184 | sscanf(buffer, "%d %d", &src, &dst); 185 | 186 | NodLP* tmpLP = cautaNodLP(pListaAdiacenta, src); 187 | 188 | if (tmpLP) { 189 | // nodul cu idVarf == src 190 | tmpLP->primListaVecini = inserareNodLS(tmpLP->primListaVecini, dst); 191 | 192 | // pentru a insera si muchia inversa (graf neorientat) 193 | // cauta nod in LP cu varf sursa nodul dst preluat din fisier 194 | tmpLP = cautaNodLP(pListaAdiacenta, dst); 195 | tmpLP->primListaVecini = inserareNodLS(tmpLP->primListaVecini, src); 196 | } 197 | else { 198 | // nu exista nodul cautat in LP 199 | printf("\nNodul cautat cu id %d nu exista.\n", src); 200 | } 201 | } 202 | 203 | // parsare lista de adiacenta 204 | NodLP* tmpLP = pListaAdiacenta; 205 | while (tmpLP) { 206 | 207 | printf("\nVarf %d cu vecinii: ", tmpLP->idVarf); 208 | 209 | NodLS* tmpLS = tmpLP->primListaVecini; 210 | while (tmpLS) { 211 | printf(" %d ", tmpLS->idNodAdiacent); 212 | 213 | tmpLS = tmpLS->next; 214 | } 215 | 216 | tmpLP = tmpLP->next; 217 | } 218 | unsigned int* vector_traversare = DF(pListaAdiacenta, 1, nrVarfuri); 219 | 220 | printf("\n\nTraversare DF graf:"); 221 | for (unsigned int i = 0; i < nrVarfuri; i++) 222 | printf(" %u", vector_traversare[i]); 223 | 224 | // dezalocare vector_traversare 225 | free(vector_traversare); 226 | 227 | 228 | //vector_traversare = BF(pListaAdiacenta, 1, nrVarfuri); 229 | //printf("\n\nTraversare BF graf:"); 230 | //for (unsigned int i = 0; i < nrVarfuri; i++) 231 | // printf(" %u", vector_traversare[i]); 232 | //// dezalocare vector_traversare 233 | //free(vector_traversare); 234 | 235 | printf("\n\n"); 236 | fclose(f); 237 | } 238 | 239 | 240 | --------------------------------------------------------------------------------