From 34703fdb61898102279b12caa16a2173f76a6676 Mon Sep 17 00:00:00 2001 From: Insaf_Ilyazov Date: Mon, 23 Dec 2024 11:53:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BC=D0=B8=D1=82=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iii.txt | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 iii.txt diff --git a/iii.txt b/iii.txt new file mode 100644 index 0000000..29a4b36 --- /dev/null +++ b/iii.txt @@ -0,0 +1,146 @@ +#define _CRT_SECURE_NO_WARNINGS + +#include +#include + +struct Node { + int data; + struct Node* next; +}; + + +struct Node* first = NULL; + +void addToHead(int value) { + struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); + + newNode->next = first; + newNode->data = value; + + first = newNode; +} + +void printList() { + struct Node* ptr = first; + while (ptr != NULL) { + printf("(%d) -> ", ptr->data); + ptr = ptr->next; + } + printf("NULL\n"); +} + +int deleteFromHead() { + int value = first->data; + struct Node* delNode = first; + first = first->next; + free(delNode); + return value; +} + +int contains(int value) { + struct Node* ptr = first; + while (ptr != NULL) { + if (ptr->data == value) { + return 1; + } + ptr = ptr->next; + } + return 0; +} + +void clearList() { + while (first != NULL) + { + struct Node* delNode = first; + first = first->next; + free(delNode); + } +} + +int sum() +{ + struct Node* ptr = first; + int s = 0; + while (ptr != NULL) { + s += ptr->data; + ptr = ptr->next; + } + return s; +} + +int evenCount() +{ + struct Node* ptr = first; + int count = 0; + while (ptr != NULL) { + if (ptr->data % 2 == 0) { + count++; + } + ptr = ptr->next; + } + return count; +} + +int oddX10() +{ + struct Node* ptr = first; + while (ptr != NULL) { + if (ptr->data % 2 != 0) { + ptr->data *= 10; + } + ptr = ptr->next; + } +} + +void element100(int i) { + struct Node* ptr = first; + int index = 0; + while (ptr != NULL) { + if (index == i) { + ptr->data = ptr->data * 100; + return; + } + ptr = ptr->next; + index++; + } +} + +void leftelement(int i) { + struct Node* ptr = first; + int index = 0; + while (ptr != NULL && index < i) { + ptr->data *= 10; + ptr = ptr->next; + index++; + } +} + + +void main() { + printList(); + + addToHead(1); + addToHead(3); + addToHead(6); + addToHead(9); + printList(); + + printf("sum = %d\n", sum()); + + printf("even numbers = %d\n", evenCount()); + + oddX10(); + printList(); + + element100(0); + printList(); + + element100(3); + printList(); + + leftelement(2); + printList(); + + +} +