Compare commits

...

2 Commits

Author SHA1 Message Date
34345e455b коммит 2 2024-12-23 11:54:30 +04:00
34703fdb61 Коммит 1 2024-12-23 11:53:05 +04:00

147
iii.txt Normal file
View File

@ -0,0 +1,147 @@
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
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();
}
dsfsdfsdf