# Thread: help me with this simple program

1. ## help me with this simple program

so I am asked to create a program with the following features:

the program is so that I can connect and disconnect countries. So say that I want to connect two countries, I input 2 integers that represent the countries. Say that country 1 and country 2 and 3 are adjacent/connected to each other and country 3 and 4 are connected. When I print the result it gives me:

Country 01 : 02 03
Country 02 : 01
Country 03 : 01 04
Country 04 : 03

My problem is that I need to store these connected countries in an array and the requirements are there can be a max of 100 countries?? So how can I do this without possibly having to declare 100 array variables for each country?

2. You need to be more specific (both to us and, I think, to yourself) about what you mean by "store these connected countries in an array". My Hat of Guessing says you want to store the adjacency matrix, which is a 2-D array.

3. Well a 2d array of size [100][100] could work, however isn't this the same as declaring 100 single array? I would also want so that I can disconnect the countries which is adjacent/connected easily. So in the example above, say that I want to disconnect country 1 and 2. Then it will be:

Country 01 : 03
Country 03 : 01 04
Country 04 : 03

4. Originally Posted by -EquinoX-
Well a 2d array of size [100][100] could work, however isn't this the same as declaring 100 single array?
Maybe? I suppose it depends on what you think "100 single array" means. I would declare it like so:
Code:
```#define MAXSIZE 100
int connections[MAXSIZE][MAXSIZE] = { {0} };```
were it I doing the work. Then if country 1 was connected to country 3, I would set both connections[1][3] and connections[3][1] to 1.

Originally Posted by -EquinoX-
I would also want so that I can disconnect the countries which is adjacent/connected easily. So in the example above, say that I want to disconnect country 1 and 2. Then it will be:

Country 01 : 03
Country 03 : 01 04
Country 04 : 03
You would unhook in very much the same way.

Edit to add: I suppose I should mention that I'm assuming country numbering is the same as array numbering. If my countries are instead numbered 1 through 100, I would subtract 1 before using the country number as an array index.

5. well that makes sense though, thanks. However, I have a concern, the instruction says that it has to be in an increasing order, so that that country 1 is connected to country 3 and 10

The output should be:
Country 01: 3 10

not

Country 01: 10 3

and there can't be duplicates also, so that's why I have to check for each row in the 2d array if that country that is going to be connected already exists or not and if it's smaller/larger than the corresponding row and column value. That's why I can't just do a [1][3] or the other way around

6. Originally Posted by -EquinoX-
well that makes sense though, thanks. However, I have a concern, the instruction says that it has to be in an increasing order, so that that country 1 is connected to country 3 and 10

The output should be:
Country 01: 3 10

not

Country 01: 10 3

and there can't be duplicates also, so that's why I have to check for each row in the 2d array if that country that is going to be connected already exists or not and if it's smaller/larger than the corresponding row and column value. That's why I can't just do a [1][3] or the other way around
None of what you just said makes any sense. If connections[1][3] is 0 (=false), there is no connection between countries 1 and 3; if connections[1][3] is 1 (=true), then there is. Order has nothing to do with it.

AND, you'll want to set connections[3][1] also, so that when you run through country 3, you will find that country 1 is connected to it.

7. so what you're trying to say here is that you just set the array values to 0 or 1?? is that right??

8. Originally Posted by -EquinoX-
so what you're trying to say here is that you just set the array values to 0 or 1?? is that right??
Yes. You should look up "adjacency matrix", since that's what you're being asked to build, but we're just keeping track of where the edges are.