首页 > > 详细

C辅导Dynamic Array, Stack, and Bag辅导R编程、R讲解

Requirement
1. General Instructions
You are given a skeleton C code in the following files:
dynArray.h
dynArray.c
stackapp.c
bag2set.c
and
Makefile
Complete the missing functions in dynArray.c, stackapp.c, and bag2set.c. Submit only these three C files via Canvas by the deadline. Do not submit the header file and compiled object files (.o).
You must use the same names of files, functions, and variables as we specified in the skeleton code. This is because our grading will be based on a script. that assumes that you use the same names.
Make sure your code compiles without errors using the provided Makefile on the ENGR server.
2. Implementation of the Dynamic Array, Stack, and Bag
Complete the seven functions in dynArray.c, listed below. Our comments in the code at the beginning of each of these functions will help you understand their purpose.
Grading policy: max 35 points
void dynArrSetCapacity(DynArr v, int newCap) = 5 points
void addDynArr(DynArr v, TYPE val) = 5 points
void removeAtDynArr(DynArr v, int idx) = 5 points
void removeDynArr(DynArr v, TYPE val) = 5 points
void pushDynArr(DynArr v, TYPE val) = 5 points
void popDynArr(DynArr v) = 5 points
int containsDynArr(DynArr v, TYPE val) = 5 points
3. Application of Stacks
Stacks can be used to check whether a mathematical expression has balanced parentheses ( ), braces { }, and brackets [ ]. For example, a balanced expression is “{(x + y), [x + (y + z)]}”. An unbalanced expression: a) Closes an unopen parenthesis/brace/bracket; or b) Closes a parenthesis/brace/bracket before closing the latest open parenthesis/brace/bracket; or c) Ends before closing all open parentheses/braces/brackets. For example, unbalanced expressions are “[x + (y + z)” or “[x + (y + z])”.
Write the function int isBalanced(char s) in stackapp.c that returns 1 if the input expression is balanced, or 0 otherwise. Alternative solutions that produce correct results BUT DO NOT USE a stack will not receive credit.
Your function should read through the input string using the function nextChar(char s), which has already been implemented for you. You may use the provided main function for testing your code.
Note that you would need to fix the data type in dynArray.h as #define TYPE char.
Grading policy: max 35 points
4. Convert a Bag into a Set
Complete the function that transforms a bag into a set in bag2set.c. A set cannot have repeated instances of the same element. Your function void bag2set(struct DynArr da) should call the functions that you implemented for the first part of HW2 in dynArray.c. In void bag2set(struct DynArr da), you should also free the memory space allocated to the input bag, since the bag is not needed any more after exiting the function.
You may use the provided main function for testing your code. Note that you would need to fix the data type in dynArray.h as #define TYPE double

 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!