-
Notifications
You must be signed in to change notification settings - Fork 0
/
StChADT.c
63 lines (55 loc) · 1.74 KB
/
StChADT.c
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
// FILENAME StChADT.c
/* ΥΛΟΠΟΙΗΣΗ ΣΤΟΙΒΑΣ ΜΕ ΠΙΝΑΚΑ *
/*ΤΑ ΣΤΟΙΧΕΙΑ ΤΗΣ ΣΤΟΙΒΑΣ ΕΙΝΑΙ ΤΥΠΟΥ char*/
#include <stdio.h>
#include "StChADT.h"
void CreateStack(StackType *Stack)
/* Λειτουργία: Δημιουργεί μια κενή στοίβα.
Επιστρέφει: Κενή Στοίβα
*/
{
Stack -> Top = -1;
// (*Stack).Top = -1;
}
boolean EmptyStack(StackType Stack)
/* Δέχεται: Μια στοίβα Stack.
Λειτουργία: Ελέγχει αν η στοίβα Stack είναι κενή.
Επιστρέφει: True αν η Stack είναι κενή, False διαφορετικά
*/
{
return (Stack.Top == -1);
}
boolean FullStack(StackType Stack)
/* Δέχεται: Μια στοίβα Stack.
Λειτουργία: Ελέγχει αν η στοίβα Stack είναι γεμάτη.
Επιστρέφει: True αν η Stack είναι γεμάτη, False διαφορετικά
*/
{
return (Stack.Top == (StackLimit - 1));
}
void Push(StackType *Stack, StackElementType Item)
/* Δέχεται: Μια στοίβα Stack και ένα στοιχείο Item.
Λειτουργία: Εισάγει το στοιχείο Item στην στοίβα Stack αν η Stack δεν είναι γεμάτη.
Επιστρέφει: Την τροποποιημένη Stack.
Έξοδος: Μήνυμα γεμάτης στοίβας, αν η στοίβα Stack είναι γεμάτη
*/
{
if (!FullStack(*Stack)) {
Stack -> Top++;
Stack -> Element[Stack -> Top] = Item;
} else
printf("Full Stack...");
}
void Pop(StackType *Stack, StackElementType *Item)
/* Δέχεται: Μια στοίβα Stack.
Λειτουργία: Διαγράφει το στοιχείο Item από την κορυφή της Στοίβας αν η Στοίβα δεν είναι κενή.
Επιστρέφει: Το στοιχείο Item και την τροποποιημένη Stack.
Έξοδος: Μήνυμα κενής στοίβας αν η Stack είναι κενή
*/
{
if (!EmptyStack(*Stack)) {
*Item = Stack -> Element[Stack -> Top];
Stack -> Top--;
} else
printf("Empty Stack...");
}