Witam!
Mam problem zaimplementowaniem stosu w postaci struktury. Konkretnie problemem jest funkcja umieszczająca nowy element na szczycie stosu. Kiedy badam program krok po kroku, na końcu funkcji push(S,x) trafia do tablicy imitującej mój stos, jednak kiedy funkcja się zakończy, na standardowym wyjściu dostaję jakąś randomową liczbę całkowitą.
Mój kod:
#include <stdio.h>
struct stack
{
int A[100];
int top;
};
void push(struct stack S, int x)
{
S.top=S.top+1;
if(S.top>100)
printf("!BŁĄÐ! - PRZEPEŁNIENIE");
else
S.A[S.top-1]=x;
}
int main()
{
struct stack S;
S.top=0;
push(S,15);
int a=S.A[0];
printf("%d", a);
return 0;
}
Pomysły? Z góry uprzedzam, że nie miałem wcześniej styczności ze strukturami. Każda pomoc mile widziana ;)