0

I want to use Index and ENUM given above. You can change the given function as desired, but the function parameters should remain constant . This code work without changing the content of the main function I just try it for days. But I'cant. I'am new to coding. I hope you are help me. And why am I get so much stack like that you can write your suggestions for me.

#include<iostream>
#include<vector>
#include <map>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
enum DIR
{
    DOWN = 1, RIGHT = 2
};
struct Index
{
    int i, j;
    Index(int _i, int _j)
    {
        i = _i; j = _j;
    }
};


int MinimumCostPath(vector<vector<int>>& M, vector<Index>& Path)
{    

}
int main() {
    vector<vector<int>> M = { {0, 1, 5},
                              {2, 4, 2},
                              {1, 3, 0} };
    vector<Index> Path;
    vector<Index> sol = { Index(0, 0), Index(1, 0), Index(2, 0), Index(2, 1), Index(2, 2) };
    int cost = MinimumCostPath(M, Path);
    if (cost != 6) return 0;
    if (Path.size() != sol.size()) return 0;
    for (size_t i = 0; i < sol.size(); i++) {
        if (sol[i].i != Path[i].i) return 0;
        if (sol[i].j != Path[i].j) return 0;
    } //end-for
    return 10;
    cout<<cost<<endl;

} 
caffeine
  • 1
  • 3
  • 1
    This question is rather unclear. What issues are you facing specifically? – cigien Jun 07 '20 at 14:09
  • 1
    And when you used your debugger to run your program, what did you see? This is precisely what a debugger is for. If you don't know how to use a debugger this is a good opportunity to learn how to use it to run your program one line at a time, monitor all variables and their values as they change, and analyse your program's logical execution flow. Knowing how to use a debugger is a required skill for every C++ developer, no exceptions. With your debugger's help you should be able to quickly find all bugs in this and all future programs you write, without having to ask anyone for help. – Sam Varshavchik Jun 07 '20 at 14:10
  • [Why should I not #include ?](https://stackoverflow.com/q/31816095/5910058) / [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/q/1452721/5910058) – Jesper Juhl Jun 07 '20 at 14:20
  • Why `return 10;` at the end of `main`? Why not either `return EXIT_SUCCESS;` or `return EXIT_FAILURE;`? Does `10` have some special meaning to whatever is invoking your program? – Jesper Juhl Jun 07 '20 at 14:24
  • `int n;` - Why a global variable? And why on earth would you name a global something as generic as `n`? Where do you even initialize that thing? – Jesper Juhl Jun 07 '20 at 14:26
  • `int A[3][3];` - I'd *strongly* suggest forgetting about C-style arrays and instead use `std::array` or `std::vector`. – Jesper Juhl Jun 07 '20 at 14:28
  • `Index(int _i, int _j) { i = _i; j = _j; }` - Don't use the constructor body to assign to variables. *Initialize* them in the constructors initialization list instead: `Index(int _i, int _j) : i(_i), j(_j) {}` – Jesper Juhl Jun 07 '20 at 14:34
  • that was the real form main function kind a test function if code can skip all test it is return 10 – caffeine Jun 07 '20 at 14:43

0 Answers0