Code Monkey home page Code Monkey logo

monty's Introduction

Below is the pseudo code:

main function: if argc == 2: read file in argv[1] if file cannot be read: exit with EXIT_FAILURE else: declare buffer = NULL declare buffer_size = 0 declare line_number = 1

	while (getline()):
		declare opcode = strtok(buffer, " ")
		declare arg = atoi(strtok(NULL, " "))

		check if !(opcode is push or pall or pint or pop or swap) or arg is not number:
			free_stack()
			print line number {line_number} failed
			exit with EXIT_FAILURE
		else:
			implement commands
			line_number ++

else: print an error exit with EXIT_FAILURE

typedef struct stack_s { int n; struct stack_s *prev; struct stack_s *next; } stack_t;

push function (value): declare and allocate node if new_node not created: exit with EXIT_FAILURE else: node->n = value;

	if top exists:
		top->prev = node

	node->next = top;
	npde->prev = null;
	top = node;

	return node;

pall: declare temp_head = top; for (; temp_head; temp_head = temp_head->next) print temp_head->n \n

pint: if (top exist) print top->n else: print {line_number} can't pint, stack empty exit with EXIT_FAILURE

pop declare temp_head; if (top exists) temp_head = top; top = top->next; top->prev = NULL; free(temp_head)

swap: if (head && head->next) declare temp_n temp_n = head->n head-> = head->next->n head->next->n = temp_n else: print stack too shor exit with EXIT_FAILURE

add: if (head && head->next) head->next->n += head->n pop() else: print stack too shor exit with EXIT_FAILURE nop: return

monty's People

Contributors

thaikum avatar vanbasten01 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.