113

#include "stack.h"
#include <string.h>
pNode VISIT(pNode s, pNode p)
{
	pNode f = s->next;
	while (f != NULL && f != p) {
		f = pop(s);
	}
	p = push(s);
	printf("%s
", p->c); return s->next; } pNode BACK(pNode s, pNode p) { if (p->next == NULL) { printf("Ignore
"); return p; } p = p->next; printf("%s
", p->c); return p; } pNode FORWARD(pNode s, pNode p) { pNode tmp = s->next; if (tmp == p) { printf("Ignore
"); return p; } while (tmp != NULL && tmp->next != p) { tmp = tmp->next; } p = tmp; printf("%s
", p->c); return p; } void QUIT(pNode s) { destroy(s); } int match(char *a, char *b) { if (strlen(a) != strlen(b)) return 0; while(*a != '\0' && *b != '\0') { if (*a != *b) return 0; a++; b++; } return 1; } int main() { pNode s = init(); pNode p; char a[10] = "VISIT", b[10] = "BACK", c[10] = "FORWARD", d[10] = "QUIT; p = VISIT(s, p); p = VISIT(s, p); p = VISIT(s, p); p = VISIT(s, p); tra(s); p = BACK(s, p); p = BACK(s, p); p = FORWARD(s, p); p = FORWARD(s, p); p = FORWARD(s, p); p = BACK(s, p); p = BACK(s, p); p = BACK(s, p); p = VISIT(s, p); p = VISIT(s, p); p = VISIT(s, p); p = VISIT(s, p); tra(s); QUIT(s); return 0; }

좋은 웹페이지 즐겨찾기