Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main(void)
- {
- char* arrayPointer = NULL;
- int dynamicSize, point1, point2;
- float input = 0;
- string key;
- cout << "How many vertices? ";
- cin >> dynamicSize;
- cout << endl;
- arrayPointer = new char[dynamicSize];
- int** graph = new int*[dynamicSize];
- for (int i = 0; i < dynamicSize; i++) {
- graph[i] = new int[dynamicSize];
- }
- for (int i = 0; i < dynamicSize; i++)
- {
- for (int j = 0; j < dynamicSize; j++)
- {
- graph[i][j] = 0;
- }
- }
- for (int i = 0; i < dynamicSize; i++) {
- cout << "What is the label for vertex " << i+1 << "? ";
- cin >> arrayPointer[i];
- }
- cout << "Define an edge by listing a pair of vertices, i.e. \"AB\", or -1 to stop." << endl;
- cin >> key;
- while (key != "-1")
- {
- for (int i = 0; i < dynamicSize; i++)
- {
- if (arrayPointer[i] == key[0])
- {
- point1 = i;
- break;
- }
- }
- for (int i = 0; i < dynamicSize; i++)
- {
- if (arrayPointer[i] == key[1])
- {
- point2 = i;
- break;
- }
- }
- cout << "Added edge " << key[0] << "->" << key[1] << endl;
- graph[point1][point2] = 1;
- cout << "Define an edge by listing a pair of vertices, i.e. \"AB\", or -1 to stop." << endl;
- cin >> key;
- }
- cout << "Your edges are: ";
- for (int i = 0; i < dynamicSize; i++)
- {
- for (int j = 0; j < dynamicSize; j++)
- {
- if (graph[i][j] == 1)
- {
- cout << arrayPointer[i] << arrayPointer[j] << " ";
- }
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement