File tree 2 files changed +17
-22
lines changed
2 files changed +17
-22
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,15 @@ bool is_valid(Array<string> & infix) {
196
196
return true ;
197
197
}
198
198
199
+ // COMMENT You should move the priority to the nodes. The reasoning is because
200
+ // you violate the DIP. If you want to add new operators to your calculator, then
201
+ // you must update this method to understands its priority. Also, the concrete
202
+ // builder should be handling the priority.
203
+
204
+ // SOLUTION:
205
+ //
206
+ // set _priority in Binary_Op_Node and use it in child node classes.
207
+
199
208
/* *
200
209
* Returns operator priority to use for order-of-operations
201
210
* @param: std::string some operator in string format
@@ -324,6 +333,14 @@ int main(int argc, char * argv[]) {
324
333
325
334
// enqueue valid expression, exception if invalid
326
335
if (is_valid (infix)) {
336
+
337
+ // COMMENT: Do not go from infix to postfix then to tree. Instead,
338
+ // go directly from infix to tree. The extra step is not necessary.
339
+
340
+ // SOLUTION:
341
+ //
342
+ // It's to build function get expression tree from infix queue instead of postfix
343
+
327
344
// get postfix
328
345
Queue<string> postfix = infix_to_postfix (infix);
329
346
Original file line number Diff line number Diff line change 1
- // //////////////////////////////////////////////////////////////////////////////
2
- //
3
- // Author: Ibrahim Sardar
4
- // Class: CSCI 363
5
- // Filename: div_Node_P.h
6
- // Date: 11/20/2017
7
- // Description: Headers for div_Node_P class.
8
- //
9
- // //////////////////////////////////////////////////////////////////////////////
10
- //
11
- // Honor Pledge:
12
- //
13
- // I pledge that I have neither given nor received any help on this assignment.
14
- //
15
- // ibsardar
16
- //
17
- // //////////////////////////////////////////////////////////////////////////////
18
- //
19
- // Copyright (c) 2017 Copyright Holder All seconds Reserved.
20
- //
21
- // //////////////////////////////////////////////////////////////////////////////
22
-
23
1
#ifndef _DIVIDE_NODE_H_
24
2
#define _DIVIDE_NODE_H_
25
3
You can’t perform that action at this time.
0 commit comments