Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/src/games/klondike/stack.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <draw.h>
#include "klondike.h"

Cardstack*
stackinit(int n, int upad, int dpad, int sz)
{
	Cardstack *cs;

	cs = malloc(sizeof(Cardstack));
	cs->sz = sz;
	cs->n = n;
	cs->upad = upad;
	cs->dpad = dpad;
	cs->p = ZP;
	cs->c = malloc(sz*sizeof(Card*));
	return cs;
}

Card*
pop(Cardstack *cs)
{
	if(cs->n == 0)
		return nil;
	return cs->c[--cs->n];
}

Card*
top(Cardstack *cs)
{
	if(cs->n == 0)
		return nil;
	return cs->c[cs->n-1];
}

void
push(Cardstack *cs, Card *c)
{
	if(cs->n < cs->sz)
		cs->c[cs->n++] = c;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.