Lab4/Lab_20/Lab_20/Z_6.cpp
2024-11-19 15:31:13 +04:00

78 lines
1020 B
C++

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int Iz1;
struct Node {
int data;
struct Node* next;
};
struct Node* first = NULL;
void printList() {
struct Node* ptr = first;
while (ptr != NULL) {
printf("(%d) -> ", ptr->data);
ptr = ptr->next;
}
printf("NULL\n");
}
void addToHead(int value) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->next = first;
newNode->data = value;
first = newNode;
}
void elLeftIx10(int value) {
struct Node* ptr = first;
int i = 0;
while (ptr != NULL) {
if (i < value) {
ptr->data *= 10;
}
ptr = ptr->next;
i++;
}
}
void clearList() {
while (first != NULL)
{
struct Node* delNode = first;
first = first->next;
free(delNode);
}
}
void main() {
first = NULL;
printList();
addToHead(1);
addToHead(3);
addToHead(8);
printList();
printf("-------------------------------------------\n");
elLeftIx10(1);
printList();
elLeftIx10(2);
printList();
clearList();
printList();
}