work in progress...1

This commit is contained in:
ada.dmitry
2023-05-16 09:40:30 +03:00
parent 0cf222ed89
commit 58a2573b52
14 changed files with 224 additions and 165 deletions
+38 -29
View File
@@ -1,21 +1,20 @@
#include "head.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
Stack get(Stack *l, int n) {
if (n > len(l))
exit(3);
int i;
for (i = 0; i < n; i++) {
void linked_print(Stack *l)
{
while (l != NULL)
{
printf("%lF\n", l->x);
l = l->next;
}
return *l;
}
Stack *add_head(Stack *l, double x) {
if (l == NULL) {
Stack *add_head(Stack *l, double x)
{
if (l == NULL)
{
l = malloc(sizeof(Stack));
if (l == NULL)
exit(1);
@@ -23,7 +22,8 @@ Stack *add_head(Stack *l, double x) {
l->next = NULL;
}
if (l->x == 0.0) {
if (l->x == 0.0)
{
l->x = x;
l->next = NULL;
return l;
@@ -38,26 +38,12 @@ Stack *add_head(Stack *l, double x) {
return tmp;
}
void stack_print(Stack *l) {
while (l != NULL) {
printf("%lF\n", l->x);
l = l->next;
}
}
int len(Stack *l) {
int ans = 0;
while (l != NULL) {
ans++;
l = l->next;
}
return ans;
}
Stack *del_head(Stack *l) {
Stack *del_head(Stack *l)
{
if (l == NULL)
return NULL;
else if (l->next == NULL) {
else if (l->next == NULL)
{
free(l);
l = NULL;
return NULL;
@@ -66,4 +52,27 @@ Stack *del_head(Stack *l) {
free(l);
l = NULL;
return tmp;
}
int len(Stack *l)
{
int res = 0;
while (l != NULL)
{
res++;
l = l->next;
}
return res;
}
Stack get(Stack *l, int n)
{
if (n > len(l))
exit(3);
int i;
for (i = 0; i < n; i++)
{
l = l->next;
}
return *l;
}