'Runtime error in Graph Program created using c++

I am trying to create a program to represent Graph using Adjacency List. In that I have created a menu-driven program and implemented non-class functions to create the graph, create edges between the vertices and to display the graph. The main question is to represent a map of area in the form of graph and use single characters (like 'a','b' or 'c' etc) to represent the cities. Following is the code:

#include<iostream>
using namespace std;

class Graph
{
    public:
    char city;
    int distance;
    Graph *next;
};

Graph **graph=new Graph*[20];
int size;

void display()
{
    for(int i=0;i<size;i++)
    {
        Graph *temp=graph[i];
        while(temp!=NULL)
        {
            cout<<temp->city<<"--"<<temp->distance<<"--";
            if(temp->next==NULL)
            cout<<"NULL"<<endl;
        }
    }
}

void edges()
{
    for(int i=0;i<size;i++)
    {
        for(int j=0;j<i;j++)
        {
            if(i==j)
            continue;
            
            Graph *temp=graph[i],*node=new Graph;
            char input;
            cout<<"\nIs there connection between " << graph[i]->city << " and " << graph[j]->city << "? Enter y or n: ";
            cin>>input;
            if(input=='y' || input=='Y')
            {
                cout<<"\nEnter the distance between them:";
                cin>>node->distance;
                temp->next=node;
                temp=temp->next;
                temp->next=NULL;
            }
        }
        cout<<endl;
    }
    cout<<"Edges Created Successfully\n";
    
}

void create()
{
    cout<<"Enter the number of cities:";
    cin>>size;
    cout<<"Enter "<<size<<" cities\n";
    for(int i=0;i<size;i++)
    {
        cout<<"City number "<<i+1<<":";
        cin>>graph[i]->city;
        cout<<endl;
    }
}

int main()
{
    while(true)
    {
        int choice;
        cout<<"\n1.Create a graph\n";
        cout<<"2.Create the connections between the vertices\n";
        cout<<"3.Display the graph\n";
        cout<<"4.Exit\n";
        cout<<"Enter your choice:";
        cin>>choice;
        switch(choice)
        {
            case 1:
            create();
            break;
            
            case 2:
            edges();
            break;
            
            case 3:
            display();
            break;
            
            case 4:
            exit(0);
            break;
            
            default:
            cout<<"Invalid Choice"<<endl;
            break;
        }
    }
}

The error I am getting is : Whenever I run the program, the program terminates unexpectedly after taking 3rd city as input. It does not allow me to take further inputs as well as to perform other operations. Please help me as this error is quite new to me. I think the cause of the error might be due to dynamically created Graph pointers array. But it is just a guess and I do not know the real cause of this problem.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source