mirror of
https://github.com/ada-dmitry/prog.l_ada.git
synced 2026-09-24 09:10:14 +00:00
work in progress...1
This commit is contained in:
+38
-29
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user