Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, m;
- char d;
- cout << "Enter the number of routers : ";
- cin >> n;
- cout << "\nFind new routing table for : ";
- cin >> d;
- cout << "\nEnter the number of neighbours : ";
- cin >> m;
- char neighbours[m];
- for (int i = 0 ; i < m ; i++) {
- cout << "\nEnter the neighbour of " << d << " : ";
- cin >> neighbours[i];
- }
- //initialize the matrix:
- int arr[50][50];
- for (int i = 0 ; i < n ; i++) {
- for (int j = 0 ; j < m ; j++) {
- arr[i][j] = -1;
- }
- }
- //array of vertex names:
- char ch[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
- //Input for matrix:
- for (int i = 0 ; i < n ; i++) {
- for (int j = 0 ; j < m; j++) {
- if (ch[i] == neighbours[j]) {
- arr[i][j] = 0;
- }
- if (arr[i][j] == -1) {
- cout << "\nEnter distance between " << ch[i] << " - " << neighbours[j] << " : ";
- cin >> arr[i][j];
- }
- }
- }
- //Display above table:
- for (int i = 0 ; i < m ; i++) {
- cout << " " << neighbours[i] << "\t";
- }
- cout << endl;
- for (int i = 0; i < n ; i++) {
- for ( int j = 0 ; j < m ; j++) {
- cout << ch[i] << "\t" << arr[i][j] << "\t";
- }
- cout << "\n";
- }
- //Ask for delay time:
- int t[m];
- for (int i = 0 ; i < m ; i++) {
- cout << "\n Enter delay time for " << d << neighbours[i] << " : ";
- cin >> t[i];
- }
- //Initialize array for new routing table
- int R[50];
- for (int i = 0 ; i < n ; i++) {
- R[i] = 0;
- }
- int p = 0;
- //find minimum and add value to new routing table
- for (int i = 0; i < n; i++) {
- int min = 999;
- for (int j = 0 ; j < m; j++) {
- if (arr[i][j] < min && arr[i][j] != -1) {
- min = arr[i][j];
- p = j;
- }
- }
- R[i] = min + t[p];
- }
- //Display the new routing table
- for (int i = 0 ; i < n ; i++) {
- if (ch[i] == d) {
- R[i] = 0;
- cout << R[i] << endl;
- }
- else {
- cout << R[i] << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement