Initial commit
This commit is contained in:
3
Assigments/2/A2src/A2src/.gitignore
vendored
Normal file
3
Assigments/2/A2src/A2src/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
*.result
|
||||
Stack.o
|
||||
Stack
|
8
Assigments/2/A2src/A2src/.idea/.gitignore
generated
vendored
Normal file
8
Assigments/2/A2src/A2src/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
21
Assigments/2/A2src/A2src/.idea/deployment.xml
generated
Normal file
21
Assigments/2/A2src/A2src/.idea/deployment.xml
generated
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
|
||||
<serverData>
|
||||
<paths name="Remote Host (49b5fb53-a681-451a-bd64-ec62856cba1b)">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping local="$PROJECT_DIR$" web="/" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
<paths name="Remote Host (86990d2b-6fb9-4298-a6b4-8994ba541314)">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping local="$PROJECT_DIR$" web="/" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
</serverData>
|
||||
</component>
|
||||
</project>
|
7
Assigments/2/A2src/A2src/.idea/discord.xml
generated
Normal file
7
Assigments/2/A2src/A2src/.idea/discord.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="ASK" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
19
Assigments/2/A2src/A2src/.idea/misc.xml
generated
Normal file
19
Assigments/2/A2src/A2src/.idea/misc.xml
generated
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MakefileSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<MakefileProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="version" value="2" />
|
||||
</MakefileProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
<component name="MakefileWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
||||
</project>
|
20
Assigments/2/A2src/A2src/Data/compound_test1.expected
Normal file
20
Assigments/2/A2src/A2src/Data/compound_test1.expected
Normal file
@ -0,0 +1,20 @@
|
||||
5
|
||||
10
|
||||
15
|
||||
20
|
||||
25
|
||||
failed push
|
||||
25
|
||||
20
|
||||
1
|
||||
2
|
||||
failed push
|
||||
2
|
||||
2
|
||||
1
|
||||
Successfully executed 12 instructions
|
||||
|_ 5 _|
|
||||
|_ 10 _|
|
||||
|_ 15 _|
|
||||
|_ 1 _|
|
||||
4 elements
|
15
Assigments/2/A2src/A2src/Data/compound_test1.input
Normal file
15
Assigments/2/A2src/A2src/Data/compound_test1.input
Normal file
@ -0,0 +1,15 @@
|
||||
u 5
|
||||
u 10
|
||||
u 15
|
||||
u 20
|
||||
u 25
|
||||
u 30
|
||||
o
|
||||
o
|
||||
u 1
|
||||
u 2
|
||||
u 3
|
||||
e
|
||||
o
|
||||
e
|
||||
x
|
3
Assigments/2/A2src/A2src/Data/compound_test2.expected
Normal file
3
Assigments/2/A2src/A2src/Data/compound_test2.expected
Normal file
@ -0,0 +1,3 @@
|
||||
failed peek
|
||||
Successfully executed 0 instructions
|
||||
0 elements
|
2
Assigments/2/A2src/A2src/Data/compound_test2.input
Normal file
2
Assigments/2/A2src/A2src/Data/compound_test2.input
Normal file
@ -0,0 +1,2 @@
|
||||
e
|
||||
x
|
22
Assigments/2/A2src/A2src/Data/compound_test3.expected
Normal file
22
Assigments/2/A2src/A2src/Data/compound_test3.expected
Normal file
@ -0,0 +1,22 @@
|
||||
failed peek
|
||||
failed peek
|
||||
failed pop
|
||||
5
|
||||
5
|
||||
5
|
||||
10000
|
||||
invalid instruction d
|
||||
invalid instruction p
|
||||
11100
|
||||
10010
|
||||
201
|
||||
-10
|
||||
-10
|
||||
-10
|
||||
201
|
||||
Successfully executed 11 instructions
|
||||
|_ 10000 _|
|
||||
|_ 11100 _|
|
||||
|_ 10010 _|
|
||||
|_ 201 _|
|
||||
4 elements
|
31
Assigments/2/A2src/A2src/Data/compound_test3.input
Normal file
31
Assigments/2/A2src/A2src/Data/compound_test3.input
Normal file
@ -0,0 +1,31 @@
|
||||
e
|
||||
e
|
||||
o
|
||||
u 5
|
||||
e
|
||||
o
|
||||
u 10000
|
||||
d
|
||||
p
|
||||
u 11100
|
||||
u 10010
|
||||
u 201
|
||||
u -10
|
||||
e
|
||||
o
|
||||
e
|
||||
x
|
||||
u 10
|
||||
u 15
|
||||
u 20
|
||||
u 25
|
||||
u 30
|
||||
o
|
||||
o
|
||||
u 1
|
||||
u 2
|
||||
u 3
|
||||
e
|
||||
o
|
||||
e
|
||||
x
|
2
Assigments/2/A2src/A2src/Data/exit_test1.expected
Normal file
2
Assigments/2/A2src/A2src/Data/exit_test1.expected
Normal file
@ -0,0 +1,2 @@
|
||||
Successfully executed 0 instructions
|
||||
0 elements
|
1
Assigments/2/A2src/A2src/Data/exit_test1.input
Normal file
1
Assigments/2/A2src/A2src/Data/exit_test1.input
Normal file
@ -0,0 +1 @@
|
||||
x
|
7
Assigments/2/A2src/A2src/Data/peek_test1.expected
Normal file
7
Assigments/2/A2src/A2src/Data/peek_test1.expected
Normal file
@ -0,0 +1,7 @@
|
||||
10
|
||||
20
|
||||
20
|
||||
Successfully executed 3 instructions
|
||||
|_ 10 _|
|
||||
|_ 20 _|
|
||||
2 elements
|
4
Assigments/2/A2src/A2src/Data/peek_test1.input
Normal file
4
Assigments/2/A2src/A2src/Data/peek_test1.input
Normal file
@ -0,0 +1,4 @@
|
||||
u 10
|
||||
u 20
|
||||
e
|
||||
x
|
3
Assigments/2/A2src/A2src/Data/peek_test2.expected
Normal file
3
Assigments/2/A2src/A2src/Data/peek_test2.expected
Normal file
@ -0,0 +1,3 @@
|
||||
failed peek
|
||||
Successfully executed 0 instructions
|
||||
0 elements
|
2
Assigments/2/A2src/A2src/Data/peek_test2.input
Normal file
2
Assigments/2/A2src/A2src/Data/peek_test2.input
Normal file
@ -0,0 +1,2 @@
|
||||
e
|
||||
x
|
6
Assigments/2/A2src/A2src/Data/pop_test1.expected
Normal file
6
Assigments/2/A2src/A2src/Data/pop_test1.expected
Normal file
@ -0,0 +1,6 @@
|
||||
10
|
||||
20
|
||||
20
|
||||
Successfully executed 3 instructions
|
||||
|_ 10 _|
|
||||
1 elements
|
4
Assigments/2/A2src/A2src/Data/pop_test1.input
Normal file
4
Assigments/2/A2src/A2src/Data/pop_test1.input
Normal file
@ -0,0 +1,4 @@
|
||||
u 10
|
||||
u 20
|
||||
o
|
||||
x
|
6
Assigments/2/A2src/A2src/Data/pop_test2.expected
Normal file
6
Assigments/2/A2src/A2src/Data/pop_test2.expected
Normal file
@ -0,0 +1,6 @@
|
||||
10
|
||||
20
|
||||
20
|
||||
10
|
||||
Successfully executed 4 instructions
|
||||
0 elements
|
5
Assigments/2/A2src/A2src/Data/pop_test2.input
Normal file
5
Assigments/2/A2src/A2src/Data/pop_test2.input
Normal file
@ -0,0 +1,5 @@
|
||||
u 10
|
||||
u 20
|
||||
o
|
||||
o
|
||||
x
|
3
Assigments/2/A2src/A2src/Data/pop_test3.expected
Normal file
3
Assigments/2/A2src/A2src/Data/pop_test3.expected
Normal file
@ -0,0 +1,3 @@
|
||||
failed pop
|
||||
Successfully executed 0 instructions
|
||||
0 elements
|
2
Assigments/2/A2src/A2src/Data/pop_test3.input
Normal file
2
Assigments/2/A2src/A2src/Data/pop_test3.input
Normal file
@ -0,0 +1,2 @@
|
||||
o
|
||||
x
|
4
Assigments/2/A2src/A2src/Data/push_test1.expected
Normal file
4
Assigments/2/A2src/A2src/Data/push_test1.expected
Normal file
@ -0,0 +1,4 @@
|
||||
10
|
||||
Successfully executed 1 instructions
|
||||
|_ 10 _|
|
||||
1 elements
|
2
Assigments/2/A2src/A2src/Data/push_test1.input
Normal file
2
Assigments/2/A2src/A2src/Data/push_test1.input
Normal file
@ -0,0 +1,2 @@
|
||||
u 10
|
||||
x
|
6
Assigments/2/A2src/A2src/Data/push_test2.expected
Normal file
6
Assigments/2/A2src/A2src/Data/push_test2.expected
Normal file
@ -0,0 +1,6 @@
|
||||
10
|
||||
20
|
||||
Successfully executed 2 instructions
|
||||
|_ 10 _|
|
||||
|_ 20 _|
|
||||
2 elements
|
3
Assigments/2/A2src/A2src/Data/push_test2.input
Normal file
3
Assigments/2/A2src/A2src/Data/push_test2.input
Normal file
@ -0,0 +1,3 @@
|
||||
u 10
|
||||
u 20
|
||||
x
|
18
Assigments/2/A2src/A2src/Data/test_custom.expected
Normal file
18
Assigments/2/A2src/A2src/Data/test_custom.expected
Normal file
@ -0,0 +1,18 @@
|
||||
10
|
||||
255
|
||||
297
|
||||
297
|
||||
invalid instruction j
|
||||
297
|
||||
894
|
||||
32978
|
||||
failed push
|
||||
32978
|
||||
32978
|
||||
894
|
||||
297
|
||||
255
|
||||
Successfully executed 12 instructions
|
||||
|_ 10 _|
|
||||
|_ 255 _|
|
||||
2 elements
|
15
Assigments/2/A2src/A2src/Data/test_custom.input
Normal file
15
Assigments/2/A2src/A2src/Data/test_custom.input
Normal file
@ -0,0 +1,15 @@
|
||||
u 10
|
||||
u 255
|
||||
u 297
|
||||
e
|
||||
j
|
||||
e
|
||||
u 894
|
||||
u 32978
|
||||
u 32
|
||||
e
|
||||
o
|
||||
o
|
||||
o
|
||||
e
|
||||
x
|
114
Assigments/2/A2src/A2src/Makefile
Normal file
114
Assigments/2/A2src/A2src/Makefile
Normal file
@ -0,0 +1,114 @@
|
||||
#########################################
|
||||
# Created by Jean-Philippe Legault
|
||||
#
|
||||
# This is a comment, a comment always start with `#`
|
||||
# Indentation is primordial in a Makefile.
|
||||
# the steps for a target are always indented
|
||||
#
|
||||
##########################################
|
||||
|
||||
# compile with gcc, change this to clang if you prefer
|
||||
COMPILER = gcc
|
||||
|
||||
# The C flags to pass to gcc
|
||||
C_FLAGS = -Wall -Wextra
|
||||
|
||||
run: Stack
|
||||
.\Stack
|
||||
|
||||
# prepend the command with '@' so that Make does not print the command before running it
|
||||
help:
|
||||
@printf "available command:\n"
|
||||
@printf " make help (this command)\n"
|
||||
@printf " make Stack (to build your C program)\n"
|
||||
@printf " make test (to run every test case)\n"
|
||||
@printf " make exit_test (to run test cases against the exit instruction for your program)\n"
|
||||
@printf " make push_test (to run test cases against the push instruction for your program)\n"
|
||||
@printf " make peek_test (to run test cases against the peek instruction for your program)\n"
|
||||
@printf " make pop_test (to run test cases against the pop instruction for your program)\n"
|
||||
@printf " make compound_test (to run test cases against all the instruction for your program)\n"
|
||||
|
||||
# link our .o files to make an executable
|
||||
Stack: Stack.o
|
||||
$(COMPILER) $(C_FLAGS) -o Stack Stack.o
|
||||
|
||||
# compile the `Stack.o` file
|
||||
Stack.o: Stack.c
|
||||
$(COMPILER) $(C_FLAGS) -c Stack.c
|
||||
|
||||
#######################
|
||||
# Custom test
|
||||
test_custom: Stack
|
||||
./Stack < Data/test_custom.input > test_custom.result
|
||||
./TestPassed.sh test_custom.result Data/test_custom.expected
|
||||
|
||||
##################################################################
|
||||
# Test Cases
|
||||
test: exit_test push_test peek_test pop_test compound_test test_custom
|
||||
|
||||
##############################
|
||||
# exit test cases
|
||||
exit_test: exit_test1
|
||||
|
||||
# run our executable by passing in the text file via stdin with `<` and passing stdout to a file with `>`
|
||||
# then use a scrit to verify that the result are the same one as the one expected
|
||||
exit_test1: Stack
|
||||
./Stack < Data/exit_test1.input > exit_test1.result
|
||||
./TestPassed.sh exit_test1.result Data/exit_test1.expected
|
||||
|
||||
##############################
|
||||
# push test cases
|
||||
push_test: push_test1 push_test2
|
||||
|
||||
push_test1: Stack
|
||||
./Stack < Data/push_test1.input > push_test1.result
|
||||
./TestPassed.sh push_test1.result Data/push_test1.expected
|
||||
|
||||
push_test2: Stack
|
||||
./Stack < Data/push_test2.input > push_test2.result
|
||||
./TestPassed.sh push_test2.result Data/push_test2.expected
|
||||
|
||||
##############################
|
||||
# peek test cases
|
||||
peek_test: peek_test1 peek_test2
|
||||
|
||||
peek_test1: Stack
|
||||
./Stack < Data/peek_test1.input > peek_test1.result
|
||||
./TestPassed.sh peek_test1.result Data/peek_test1.expected
|
||||
|
||||
peek_test2: Stack
|
||||
./Stack < Data/peek_test2.input > peek_test2.result
|
||||
./TestPassed.sh peek_test2.result Data/peek_test2.expected
|
||||
|
||||
##############################
|
||||
# pop test cases
|
||||
pop_test: pop_test1 pop_test2 pop_test3
|
||||
|
||||
pop_test1: Stack
|
||||
./Stack < Data/pop_test1.input > pop_test1.result
|
||||
./TestPassed.sh pop_test1.result Data/pop_test1.expected
|
||||
|
||||
pop_test2: Stack
|
||||
./Stack < Data/pop_test2.input > pop_test2.result
|
||||
./TestPassed.sh pop_test2.result Data/pop_test2.expected
|
||||
|
||||
pop_test3: Stack
|
||||
./Stack < Data/pop_test3.input > pop_test3.result
|
||||
./TestPassed.sh pop_test3.result Data/pop_test3.expected
|
||||
|
||||
##############################
|
||||
# compound test cases
|
||||
compound_test: compound_test1 compound_test2 compound_test3
|
||||
|
||||
compound_test1: Stack
|
||||
./Stack < Data/compound_test1.input > compound_test1.result
|
||||
./TestPassed.sh compound_test1.result Data/compound_test1.expected
|
||||
|
||||
compound_test2: Stack
|
||||
./Stack < Data/compound_test2.input > compound_test2.result
|
||||
./TestPassed.sh compound_test2.result Data/compound_test2.expected
|
||||
|
||||
compound_test3: Stack
|
||||
./Stack < Data/compound_test3.input > compound_test3.result
|
||||
./TestPassed.sh compound_test3.result Data/compound_test3.expected
|
||||
|
248
Assigments/2/A2src/A2src/Stack.c
Normal file
248
Assigments/2/A2src/A2src/Stack.c
Normal file
@ -0,0 +1,248 @@
|
||||
/*******************************************************
|
||||
* Stack.c
|
||||
*
|
||||
*
|
||||
* Created by Jean-Philippe Legault
|
||||
*
|
||||
* Your task is to implement the section with the comment:
|
||||
* * TODO: finish implementing this
|
||||
******************************************************/
|
||||
|
||||
// allows the usage of `scanf` and `printf`
|
||||
#include <stdio.h>
|
||||
|
||||
// Has the macro definition for EXIT_SUCCESS
|
||||
#include <stdlib.h>
|
||||
|
||||
// allows the usage of `bool`
|
||||
#include <stdbool.h>
|
||||
|
||||
#define STACK_MAX_SIZE 5
|
||||
|
||||
/**
|
||||
* function:
|
||||
* is_whitespace
|
||||
*
|
||||
* expects:
|
||||
* a single char
|
||||
*
|
||||
* returns:
|
||||
* true when the char is a whitespace character
|
||||
* false otherwise
|
||||
*/
|
||||
bool is_whitespace(char in)
|
||||
{
|
||||
return (in == ' ' || in == '\t' || in == '\n' || in == '\r');
|
||||
}
|
||||
|
||||
/**
|
||||
* function:
|
||||
* print_stack
|
||||
*
|
||||
* expects:
|
||||
* a pointer to the root of the stack
|
||||
* a pointer to the current size of the stack
|
||||
*
|
||||
* Prints a visual representation of the current state of the stack
|
||||
*/
|
||||
void print_stack(int *stack, int *size)
|
||||
{
|
||||
for(int i=0; i<(*size); i++)
|
||||
{
|
||||
printf("|_ %d _|\n", stack[i] );
|
||||
}
|
||||
printf("%d elements\n", (*size) );
|
||||
}
|
||||
|
||||
/**
|
||||
* function:
|
||||
* push
|
||||
*
|
||||
* expects:
|
||||
* pointer to the stack
|
||||
* pointer to the size
|
||||
* the value to push
|
||||
*
|
||||
* returns:
|
||||
* true when value has been pushed
|
||||
* false otherwise
|
||||
*
|
||||
* The push function push a value to the passed in stack
|
||||
*/
|
||||
bool push(int *stack, int *size, int max_size, int to_push)
|
||||
{
|
||||
if(*size >= max_size) return false;
|
||||
stack[*size] = to_push;
|
||||
*size = *size + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* function:
|
||||
* pop
|
||||
*
|
||||
* expects:
|
||||
* pointer to the stack
|
||||
* pointer to the size
|
||||
* pointer to location to store the popped value
|
||||
*
|
||||
* returns:
|
||||
* true when value has been popped
|
||||
* false otherwise
|
||||
*
|
||||
* The pop function pops a value from the passed in stack and stores it at the to_return location.
|
||||
*/
|
||||
bool pop(int *stack, int *size, int *to_return)
|
||||
{
|
||||
if(*size <= 0) return false;
|
||||
*size = *size - 1;
|
||||
*to_return = stack[*size];
|
||||
//stack[*size] == 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* function:
|
||||
* peek
|
||||
*
|
||||
* expects:
|
||||
* pointer to the stack
|
||||
* pointer to the size
|
||||
* pointer to location to store the popped value
|
||||
*
|
||||
* returns:
|
||||
* true when value has been peeked
|
||||
* false otherwise
|
||||
*
|
||||
* The peek function looks at the top value from the stack and stores it at the to_return location.
|
||||
*/
|
||||
bool peek(int *stack, int *size, int *to_return)
|
||||
{
|
||||
if(*size <= 0) return false;
|
||||
*to_return = stack[*size-1];
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************
|
||||
* function implementation
|
||||
*/
|
||||
|
||||
/**
|
||||
* function:
|
||||
* main
|
||||
*
|
||||
* expects:
|
||||
* n/a
|
||||
*
|
||||
* returns:
|
||||
* EXIT_SUCCESS when program ends.
|
||||
*
|
||||
* while we are not instructed to exit the program
|
||||
*
|
||||
* We read in a char as an instruction :
|
||||
* 'u' for push
|
||||
* 'o' for pop
|
||||
* 'e' for peek
|
||||
* 'x' to exit the program
|
||||
*
|
||||
* if the instruction is push ('u'),
|
||||
* we read in an integer (you may assume it is a valid integer)
|
||||
* push the read value onto the stack
|
||||
* if failed
|
||||
* printf("failed push\n")
|
||||
* else
|
||||
* print the value pushed
|
||||
*
|
||||
* else if the instruction is pop ('o')
|
||||
* we execute the pop function
|
||||
* if failed
|
||||
* printf("failed pop\n")
|
||||
* else
|
||||
* print the value popped
|
||||
*
|
||||
* else if the instruction is peek ('e')
|
||||
* we execute the peek function
|
||||
* if failed
|
||||
* printf("failed peek\n")
|
||||
* else
|
||||
* print the value peeked
|
||||
*
|
||||
* else if the instruction is exit ('x')
|
||||
* we break out of the loop
|
||||
*
|
||||
* else
|
||||
* printf("invalid instruction %c\n", input_instruction);
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
// keep track of the max size and the current size of the stack
|
||||
int stack_max_size = STACK_MAX_SIZE;
|
||||
int stack_current_size = 0;
|
||||
int stack_current_value = 0;
|
||||
int popped_value = 0;
|
||||
int input_value = 0;
|
||||
|
||||
// the stack is an array located on the main() function stack frame
|
||||
int stack[stack_max_size];
|
||||
|
||||
// initialize our stack with 0 values
|
||||
for(int i=0; i < stack_max_size; i++)
|
||||
{
|
||||
stack[i] = 0;
|
||||
}
|
||||
|
||||
// count the number of instructions (peek, pop, push) that successfully happened
|
||||
int successful_instructions = 0;
|
||||
bool stop_execution = false;
|
||||
|
||||
while(!stop_execution)
|
||||
{
|
||||
// read the input instruction (a single character)
|
||||
char input_instruction = 0;
|
||||
scanf("%c", &input_instruction);
|
||||
|
||||
// the character could be a whitespace, so we need to skip those
|
||||
if(!is_whitespace(input_instruction))
|
||||
{
|
||||
if (input_instruction == 'u') {
|
||||
scanf("%d", &input_value);
|
||||
if (push(stack, &stack_current_size, stack_max_size, input_value)) {
|
||||
printf("%d\n", input_value);
|
||||
successful_instructions++;
|
||||
}
|
||||
else {
|
||||
printf("failed push\n");
|
||||
}
|
||||
}
|
||||
else if (input_instruction == 'o') {
|
||||
if (pop(stack, &stack_current_size, &popped_value)) {
|
||||
printf("%d\n", popped_value);
|
||||
successful_instructions++;
|
||||
}
|
||||
else {
|
||||
printf("failed pop\n");
|
||||
}
|
||||
}
|
||||
else if (input_instruction == 'e') {
|
||||
if (peek(stack, &stack_current_size, &stack_current_value)) {
|
||||
printf("%d\n", stack_current_value);
|
||||
successful_instructions++;
|
||||
}
|
||||
else {
|
||||
printf("failed peek\n");
|
||||
}
|
||||
}
|
||||
else if (input_instruction == 'x') {
|
||||
stop_execution = true;
|
||||
}
|
||||
else {
|
||||
printf("invalid instruction %c\n", input_instruction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Successfully executed %d instructions\n", successful_instructions);
|
||||
print_stack(stack, &stack_current_size);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
Assigments/2/A2src/A2src/Stack.exe
Normal file
BIN
Assigments/2/A2src/A2src/Stack.exe
Normal file
Binary file not shown.
30
Assigments/2/A2src/A2src/TestPassed.sh
Normal file
30
Assigments/2/A2src/A2src/TestPassed.sh
Normal file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
##########################
|
||||
#
|
||||
# Created by Jean-Philippe Legault
|
||||
#
|
||||
# This script compares two file to see if they differ from each other
|
||||
# using the `diff` command.
|
||||
#
|
||||
##########################
|
||||
|
||||
# get the two files to compare via the arguments to this script
|
||||
FILE_ONE="$1"
|
||||
FILE_TWO="$2"
|
||||
|
||||
# verify two files passed via the arguments for this script are equal using the `diff` command
|
||||
diff ${FILE_ONE} ${FILE_TWO} > /dev/null
|
||||
|
||||
# get the exit code of diff
|
||||
RETURN_CODE="$?"
|
||||
|
||||
# 0 indicates no differences were found
|
||||
if [ "${RETURN_CODE}" == "0" ]
|
||||
then
|
||||
echo -e "\n###### Passed ###### ${FILE_ONE} is equal to ${FILE_TWO} \n"
|
||||
exit 0
|
||||
else
|
||||
echo -e "\n###### Failed ###### ${FILE_ONE} is NOT equal to ${FILE_TWO} \n"
|
||||
exit 1
|
||||
fi
|
BIN
Assigments/2/A2src/Shoebottom_Isaac_A2.docx
Normal file
BIN
Assigments/2/A2src/Shoebottom_Isaac_A2.docx
Normal file
Binary file not shown.
BIN
Assigments/2/A2src/Shoebottom_Isaac_A2.pdf
Normal file
BIN
Assigments/2/A2src/Shoebottom_Isaac_A2.pdf
Normal file
Binary file not shown.
BIN
Assigments/2/A2src/Shoebottom_Isaac_A2.zip
Normal file
BIN
Assigments/2/A2src/Shoebottom_Isaac_A2.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user