-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackCommand.c
More file actions
72 lines (57 loc) · 1.44 KB
/
Copy pathstackCommand.c
File metadata and controls
72 lines (57 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// stackCommand.c
// FileDistance
//
// Created by Alessandra Lerteri Caroletta on 21/09/20.
//
#include "stackCommand.h"
#include <stdlib.h>
#include <string.h>
/*
Funzione utilizzata per creare un nuovo nodo.
Viene richiamata dalla funzione pushNode per allocare la memoria necessaria a contenere uno Stack.
*/
stackCommand *createNewNode () {
stackCommand *newNode = (stackCommand *) calloc(1,sizeof(stackCommand));
newNode->pos = 0;
newNode->character = ' ';
newNode->type = 0;
newNode->prev = NULL;
return newNode;
}
void pushCommand (stackCommand **root, unsigned int pos, char character, type_op type) {
stackCommand *nextNode = createNewNode();
nextNode->pos = pos;
nextNode->character = character;
nextNode->type = type;
nextNode->prev = *root;
*root = nextNode;
}
void popCommand (stackCommand **root) {
stackCommand * temp= *root;
if(!checkEmptyCommandStack(*root)){
*root = (*root)->prev;
free(temp);
}else {
free(*root);
}
}
char *getType (stackCommand *node) {
if(!checkEmptyCommandStack(node)){
switch (node->type) {
case SET:
return "SET";
case ADD:
return "ADD";
case DEL:
return "DEL";
}
}
else return "0";
}
int checkEmptyCommandStack (stackCommand *root) {
if(root!=NULL){
return 0;
}
return 1;
}