├── 01-struct ├── struct1 ├── struct1.c ├── struct2 ├── struct2.c ├── struct3 ├── struct3.c ├── struct4 └── struct4.c ├── 02-union ├── union └── union.c ├── 03-linkedList ├── linkedList └── linkedList.c ├── 04-queue ├── queue └── queue.c ├── 05-stack ├── stack └── stack.c └── 06-binary-tree ├── binary-tree └── binary-tree.c /01-struct/struct1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yucelalkan/data-structures/a9001b22200344ca7f7d47958fb748e6b249ac84/01-struct/struct1 -------------------------------------------------------------------------------- /01-struct/struct1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct kitap { 6 | char kitapAdi[30]; 7 | float fiyat; 8 | int sayfa; 9 | }; 10 | 11 | typedef struct { 12 | char adSoyad[30]; 13 | int yas; 14 | } yazar; 15 | 16 | int main(){ 17 | 18 | // Direct 19 | struct kitap kitap1; 20 | strcpy(kitap1.kitapAdi, "Türklerin Tarihi"); 21 | kitap1.fiyat = 17.50; 22 | kitap1.sayfa = 350; 23 | 24 | // Undirect 25 | struct kitap *kitap2 = (struct kitap *)malloc(sizeof(struct kitap)); 26 | strcpy(kitap2->kitapAdi, "Fabrika Ayarı"); 27 | kitap2->fiyat = 16.50; 28 | kitap2->sayfa = 300; 29 | 30 | // TypeDef ile Kullanım - Direct 31 | yazar yazar1; 32 | strcpy(yazar1.adSoyad, "İlber Ortaylı"); 33 | yazar1.yas = 74; 34 | 35 | // Typedef - Undirect 36 | yazar *yazar2 = (yazar *)malloc(sizeof(yazar)); 37 | strcpy(yazar2->adSoyad, "Hayati İnanç"); 38 | yazar2->yas = 60; 39 | 40 | printf("Yazar 1: %s %d \n", yazar1.adSoyad, yazar1.yas); 41 | printf("Yazar 2: %s %d", yazar2->adSoyad, yazar2->yas); 42 | 43 | return 1; 44 | } -------------------------------------------------------------------------------- /01-struct/struct2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yucelalkan/data-structures/a9001b22200344ca7f7d47958fb748e6b249ac84/01-struct/struct2 -------------------------------------------------------------------------------- /01-struct/struct2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef struct { 6 | char takimAdi[30]; 7 | int kurulus; 8 | } takim; 9 | 10 | typedef struct { 11 | char adSoyad[30]; 12 | int yas; 13 | takim takim; 14 | } futbolcu; 15 | 16 | int main(){ 17 | 18 | futbolcu ft; 19 | strcpy(ft.adSoyad, "Nurullah Aslan"); 20 | ft.yas = 20; 21 | strcpy(ft.takim.takimAdi, "Samsunspor"); 22 | ft.takim.kurulus = 1965; 23 | 24 | printf("Bilgiler: %s %d", ft.takim.takimAdi, ft.takim.kurulus); 25 | 26 | return 1; 27 | } -------------------------------------------------------------------------------- /01-struct/struct3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yucelalkan/data-structures/a9001b22200344ca7f7d47958fb748e6b249ac84/01-struct/struct3 -------------------------------------------------------------------------------- /01-struct/struct3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef struct { 6 | char takimAdi[30]; 7 | int kurulus; 8 | } takim; 9 | 10 | typedef struct { 11 | char adSoyad[30]; 12 | int yas; 13 | takim takim; 14 | } futbolcu; 15 | 16 | int main(){ 17 | 18 | takim tk; 19 | strcpy(tk.takimAdi, "Samsunspor"); 20 | tk.kurulus = 1965; 21 | 22 | futbolcu ft; 23 | strcpy(ft.adSoyad, "Burak Çalık"); 24 | ft.yas = 30; 25 | ft.takim = tk; 26 | 27 | printf("Bilgiler: %s %d", ft.takim.takimAdi, ft.takim.kurulus); 28 | 29 | return 1; 30 | } -------------------------------------------------------------------------------- /01-struct/struct4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yucelalkan/data-structures/a9001b22200344ca7f7d47958fb748e6b249ac84/01-struct/struct4 -------------------------------------------------------------------------------- /01-struct/struct4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef struct { 6 | char takimAdi[30]; 7 | int kurulus; 8 | } takim; 9 | 10 | typedef struct { 11 | char adSoyad[30]; 12 | int yas; 13 | takim *takim; 14 | } futbolcu; 15 | 16 | int main(){ 17 | 18 | takim *tk = (takim *)malloc(sizeof(takim)); 19 | strcpy(tk->takimAdi,"Samsunspor"); 20 | tk->kurulus = 1965; 21 | 22 | futbolcu ft; 23 | strcpy(ft.adSoyad, "İlyas Kubilay Yavuz"); 24 | ft.yas = 26; 25 | ft.takim = tk; 26 | 27 | printf("Bilgiler: %s %d", ft.takim->takimAdi, ft.takim->kurulus); 28 | 29 | return 1; 30 | } -------------------------------------------------------------------------------- /02-union/union: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yucelalkan/data-structures/a9001b22200344ca7f7d47958fb748e6b249ac84/02-union/union -------------------------------------------------------------------------------- /02-union/union.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Union Tanımlama - 1 5 | union ogrenci { 6 | char isim[20]; 7 | int no; 8 | float ort; 9 | }; 10 | 11 | // Union Tanımlama - 2 12 | typedef union { 13 | char isim[20]; 14 | int yas; 15 | } ogretmen; 16 | 17 | int main(){ 18 | 19 | printf("Boyut: %ld Byte \n", sizeof(union ogrenci)); 20 | 21 | union ogrenci o; 22 | 23 | strcpy(o.isim, "Yücel"); 24 | printf("İsim: %s \n", o.isim); 25 | 26 | o.no = 148; 27 | printf("No: %d \n", o.no); 28 | 29 | o.ort = 85.5; 30 | printf("Ortalama: %f \n", o.ort); 31 | 32 | // Typedef ile Kullanım 33 | ogretmen ogrt; 34 | strcpy(ogrt.isim, "İsmail"); 35 | 36 | printf("Öğretmen Adı: %s \n", ogrt.isim); 37 | 38 | ogrt.yas = 45; 39 | printf("Öğretmen Yaşı: %d", ogrt.yas); 40 | 41 | return 1; 42 | } 43 | -------------------------------------------------------------------------------- /03-linkedList/linkedList: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yucelalkan/data-structures/a9001b22200344ca7f7d47958fb748e6b249ac84/03-linkedList/linkedList -------------------------------------------------------------------------------- /03-linkedList/linkedList.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Linked List 5 | struct node { 6 | int data; 7 | struct node *next; 8 | }; 9 | 10 | // Head & Tail 11 | struct node *head = NULL; 12 | struct node *tail = NULL; 13 | 14 | // Add Node 15 | int addNode(int data){ 16 | 17 | // Linked List is empty 18 | if(head==NULL){ 19 | struct node *new = (struct node *)malloc(sizeof(struct node)); 20 | new->data = data; 21 | new->next = NULL; 22 | 23 | head = tail = new; 24 | } 25 | // Linked List's not empty 26 | else { 27 | struct node *new = (struct node *)malloc(sizeof(struct node)); 28 | new->data = data; 29 | new->next = NULL; 30 | 31 | tail->next = new; 32 | 33 | tail = new; 34 | } 35 | 36 | return 1; 37 | } 38 | 39 | // Add Node to Head 40 | int addNodeHead(int data){ 41 | // Linked List is empty 42 | if(head==NULL){ 43 | struct node *new = (struct node *)malloc(sizeof(struct node)); 44 | new->data = data; 45 | new->next = NULL; 46 | 47 | head = tail = new; 48 | } 49 | // Linked List's not empty 50 | else { 51 | struct node *new = (struct node *)malloc(sizeof(struct node)); 52 | new->data = data; 53 | new->next = head; 54 | 55 | head = new; 56 | } 57 | } 58 | 59 | // Print 60 | int print(){ 61 | printf("Linked List: "); 62 | struct node *index = head; 63 | while(index!=NULL){ 64 | printf("%d - ", index->data); 65 | index = index->next; 66 | } 67 | printf("\n"); 68 | return 1; 69 | } 70 | 71 | // Delete Node 72 | int delete(int data){ 73 | 74 | struct node *prev = NULL; 75 | struct node *index = head; 76 | 77 | // Linked List is empty 78 | if(head==NULL){ 79 | printf("Linked List is empty \n"); 80 | return 1; 81 | } 82 | 83 | // Delete Head Node 84 | if(head->data==data){ 85 | struct node *t = head; 86 | head = head->next; 87 | free(t); 88 | return 1; 89 | } 90 | 91 | // Search in Linked List 92 | while(index!=NULL && index->data!=data){ 93 | prev = index; 94 | index = index->next; 95 | } 96 | 97 | // Data not found 98 | if(index==NULL){ 99 | printf("Data not found. \n"); 100 | return 1; 101 | } 102 | 103 | // Data found 104 | prev->next = index->next; 105 | 106 | // Delete Tail Node 107 | if(tail->data==data){ 108 | tail = prev; 109 | } 110 | 111 | // Clean Memory 112 | free(index); 113 | 114 | return 1; 115 | } 116 | 117 | int main(){ 118 | 119 | addNode(10); 120 | addNode(14); 121 | addNode(16); 122 | addNode(19); 123 | 124 | addNodeHead(15); 125 | addNodeHead(7); 126 | 127 | addNode(30); 128 | 129 | print(); 130 | 131 | delete(7); 132 | print(); 133 | 134 | delete(30); 135 | print(); 136 | 137 | delete(55); 138 | 139 | delete(15); 140 | delete(10); 141 | delete(14); 142 | delete(16); 143 | delete(19); 144 | 145 | print(); 146 | 147 | delete(15); 148 | 149 | addNode(5); 150 | addNode(7); 151 | addNodeHead(3); 152 | addNodeHead(1); 153 | print(); 154 | 155 | return 1; 156 | } -------------------------------------------------------------------------------- /04-queue/queue: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yucelalkan/data-structures/a9001b22200344ca7f7d47958fb748e6b249ac84/04-queue/queue -------------------------------------------------------------------------------- /04-queue/queue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Queue Node 5 | struct node { 6 | int data; 7 | struct node *next; 8 | }; 9 | 10 | // Front & Rear 11 | struct node *front = NULL; 12 | struct node *rear = NULL; 13 | 14 | // Enqueue 15 | int enqueue(int data){ 16 | // Queue is empty 17 | if(front==NULL){ 18 | struct node *new = (struct node *)malloc(sizeof(struct node)); 19 | new->data = data; 20 | new->next = NULL; 21 | 22 | front = rear = new; 23 | } 24 | // Queue is not empty 25 | else { 26 | struct node *new = (struct node *)malloc(sizeof(struct node)); 27 | new->data = data; 28 | new->next = NULL; 29 | 30 | rear->next = new; 31 | 32 | rear = new; 33 | } 34 | 35 | return 1; 36 | } 37 | 38 | // Display Queue 39 | int display(){ 40 | 41 | // Queue is empty 42 | if(front==NULL){ 43 | printf("Queue is empty \n"); 44 | return 1; 45 | } 46 | 47 | printf("Queue: "); 48 | struct node *index = front; 49 | while(index!=NULL){ 50 | printf("%d - ", index->data); 51 | index = index->next; 52 | } 53 | 54 | printf("\n"); 55 | 56 | return 1; 57 | } 58 | 59 | // Dequeue 60 | int dequeue(){ 61 | 62 | // Queue is empty 63 | if(front==NULL){ 64 | printf("Queue is empty \n"); 65 | return 1; 66 | } 67 | 68 | struct node *temp = front; 69 | 70 | front = front->next; 71 | 72 | free(temp); 73 | 74 | return 1; 75 | } 76 | 77 | // Main 78 | int main(){ 79 | 80 | enqueue(5); 81 | enqueue(6); 82 | enqueue(8); 83 | enqueue(10); 84 | 85 | display(); 86 | 87 | dequeue(); 88 | dequeue(); 89 | display(); 90 | 91 | dequeue(); 92 | dequeue(); 93 | display(); 94 | 95 | enqueue(1); 96 | enqueue(3); 97 | display(); 98 | 99 | return 1; 100 | } 101 | -------------------------------------------------------------------------------- /05-stack/stack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yucelalkan/data-structures/a9001b22200344ca7f7d47958fb748e6b249ac84/05-stack/stack -------------------------------------------------------------------------------- /05-stack/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Stack Struct 5 | struct node { 6 | int data; 7 | struct node *next; 8 | }; 9 | 10 | // Top 11 | struct node *top = NULL; 12 | 13 | // Push 14 | int push(int data){ 15 | // Stack is empty 16 | if(top==NULL){ 17 | struct node *new = (struct node *)malloc(sizeof(struct node)); 18 | new->data = data; 19 | new->next = NULL; 20 | 21 | top = new; 22 | } 23 | // Stack's not empty 24 | else { 25 | struct node *new = (struct node *)malloc(sizeof(struct node)); 26 | new->data = data; 27 | new->next = top; 28 | 29 | top = new; 30 | } 31 | 32 | return 1; 33 | } 34 | 35 | // Display 36 | int display(){ 37 | // Stack is empty 38 | if(top==NULL){ 39 | printf("Stack is empty \n"); 40 | return 1; 41 | } 42 | 43 | struct node *index = top; 44 | while(index!=NULL){ 45 | printf("%d - ", index->data); 46 | index = index->next; 47 | } 48 | 49 | printf("\n"); 50 | 51 | return 1; 52 | } 53 | 54 | // Pop 55 | int pop(){ 56 | // Stack is empty 57 | if(top==NULL){ 58 | printf("Stack is empty. \n"); 59 | return 1; 60 | } 61 | 62 | struct node *temp = top; 63 | 64 | top = top->next; 65 | 66 | free(temp); 67 | 68 | return 1; 69 | } 70 | 71 | // Main 72 | int main(){ 73 | 74 | push(1); 75 | push(2); 76 | push(4); 77 | 78 | display(); 79 | 80 | pop(); 81 | pop(); 82 | display(); 83 | 84 | pop(); 85 | display(); 86 | 87 | push(7); 88 | push(9); 89 | push(13); 90 | display(); 91 | 92 | return 1; 93 | } -------------------------------------------------------------------------------- /06-binary-tree/binary-tree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yucelalkan/data-structures/a9001b22200344ca7f7d47958fb748e6b249ac84/06-binary-tree/binary-tree -------------------------------------------------------------------------------- /06-binary-tree/binary-tree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node 5 | { 6 | int data; 7 | struct node *left; 8 | struct node *right; 9 | }; 10 | 11 | struct node *newNode(int data) 12 | { 13 | struct node *new = malloc(sizeof(struct node)); 14 | new->data = data; 15 | new->left = NULL; 16 | new->right = NULL; 17 | 18 | return new; 19 | } 20 | 21 | int main() 22 | { 23 | // Root 24 | struct node *root = newNode(1); 25 | 26 | root->left = newNode(2); 27 | root->right = newNode(3); 28 | 29 | root->left->left = newNode(4); 30 | root->left->right = newNode(5); 31 | 32 | root->right->left = newNode(6); 33 | root->right->right = newNode(7); 34 | 35 | printf("Root : %d \n", root->data); 36 | printf("Root->Left : %d \n", root->left->data); 37 | printf("Root->Right: %d \n", root->right->data); 38 | 39 | printf("Root->Left->Left: %d \n", root->left->left->data); 40 | printf("Root->Left->Right: %d \n", root->left->right->data); 41 | 42 | printf("Root->Right->Left: %d \n", root->right->left->data); 43 | printf("Root->Right->Right: %d \n", root->right->right->data); 44 | 45 | return 1; 46 | } 47 | --------------------------------------------------------------------------------