codice:
/*
### Copyright (c) 2004 Luca Francesca
### This script is provided under the terms of the GNU General Public License
### (see http://www.gnu.org/licenses/gpl.html for the full license text.)
*/
#include <stdio.h>
#include <stdlib.h>
#include "Common.h"
#define SIZE 20
typedef struct _Stack *Stack;
typedef int base_type;
struct _Stack
{
base_type stack[SIZE];
int sp;
};
Stack Init(base_type val);
void Push(Stack st, base_type val);
base_type Pop(Stack st);
void Delete(Stack st);
int main(int argc, char *argv[])
{
Stack st = Init(0);
int i = 0;
for(i; i <= SIZE; ++i)
{
Push(st, i);
}
for(i = 0; i <= SIZE; ++i)
{
printf("%d\n", Pop(st));
}
Delete(st);
char exit;
scanf("%c", &exit);
return 0;
}
Stack Init(base_type val)
{
Stack tmp;
tmp = malloc(sizeof(struct _Stack));
tmp->sp = 0;
tmp->stack[tmp->sp++] = val;
return tmp;
}
void Push(Stack st, base_type val)
{
if(st->sp == SIZE)
return;
st->stack[st->sp++] = val;
}
base_type Pop(Stack st)
{
if(st->sp == 0)
return 0;
else
return st->stack[--st->sp];
}
void Delete(Stack st)
{
SAFE_DELETE(st)
}
Risolto