"adjacency list representation of graph" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "adjacency list representation of graph" answered properly. Developers are finding an appropriate answer about adjacency list representation of graph related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like adjacency list representation of graph. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on adjacency list representation of graph. 

adjacency list representation of graph

By ujjwal sotraujjwal sotra on May 22, 2021
//adjacency list implementation;addedge,check if edge exist,delete an edge,display
/*            0----->1--------
              |        |     |-->4
              |->2---->|->3---
*/
   
#include <iostream>

using namespace std;
#define v 5
class node
{
public:
    int data;
    node*next;
};
node*adjlist[v];
void init()
{
    for(int i=0;i<v;i++)
    {
        adjlist[i]=NULL;
    }
}
void addedge(int str,int en)
{
    node*temp=new node;
    temp->data=en;
    temp->next=adjlist[str];
    adjlist[str]=temp;
}
void hasedge(int str,int en)
{
    node*temp=new node;
    temp=adjlist[str];
    while(temp!=NULL)
    {
        if(temp->data==en)
        {
            cout<<"yes:";
        }
        temp=temp->next;
    }

}
void remove(int str,int en)
{
    if(adjlist[str]==NULL)
    {
        return;
    }

    if(adjlist[str]->data==en)
    {
        node*temp=new node;
        temp=adjlist[str];
        adjlist[str]=adjlist[str]->next;
        delete temp;
    }
    else
    {
        node *ptr=new node;
        ptr=adjlist[str];
        while(ptr->next!=NULL)
        {
            node*temp=new node;
            if(ptr->next->data==en)
            {

                temp=ptr->next;
                ptr->next=ptr->next->next;
                delete temp;
                break;
            }
            ptr=ptr->next;
        }
    }
}
void display()
{
    for(int i=0;i<v;i++)
    {
        node*temp=new node;
        cout<<"adjlist[]"<<i<<endl;
        temp=adjlist[i];
        while(temp!=NULL)
        {
            cout<<temp->data<<" ";
            temp=temp->next;
        }
        cout<<endl;
    }
}

int main()
{
    init();
    addedge(0,1);
    addedge(0,2);
    addedge(0,3);
    addedge(1,3);
    addedge(1,4);
    addedge(2,3);
    addedge(3,4);
    display();
    hasedge(0,3);
    hasedge(0,4);
    remove(0,1);
    remove(1,4);
    display();
    return 0;
}

Add Comment

0

All those coders who are working on the C++ based application and are stuck on adjacency list representation of graph can get a collection of related answers to their query. Programmers need to enter their query on adjacency list representation of graph related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about adjacency list representation of graph for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of adjacency list representation of graph while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "adjacency list representation of graph". Visit this developer's friendly online web community, CodeProZone, and get your queries like adjacency list representation of graph resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "adjacency list representation of graph"

View All C++ queries

C++ queries related to "adjacency list representation of graph"

adjacency list representation of graph adjacency matrix of a directed graph delete and search edge in adjacency matrix of a graph graph using djacency matrix c++ bfs traversal of graph in c graph c++ find the graph is minimal spanig tree or not Dijkstra's Weighted Graph Shortest Path in c++ graph using queue c++ Graph Adjacent Node in c++ weighted graph c++ list conda environments how to print list in c++ grocery shopping list c++ chegg c++ remove multiple items from list c++ linked list clear delete a head node in link list how to make a list in c++ traverse through list c++ cpp std list example how to get an element in a list c++ cpp linked list list in cpp linked list insertion in c++ member initializer list in c++ initialization list c++ how to write C++ list c++ append to list c++ class member initializer list c++ remove item from list c++ com port list circular queue using linked list in c++ linked list in c++ stl list in c++ stl c++ iterate through constant list list clear c++ list of products on e commerce websites c++ list pop back infix to prefix using cpp linked list program Given the following declarations below. Write a loop to read a list of numbers from the keyboard terminated by -999 and store the even numbers (skip over the odd numbers) in the vector v. clean list widget qt linked list in c++ using class insert delete display in array error: invalid use of template-name without an argument list qt widget list set selected c++ initialization list C++ drop last element of list c++ argument list for class template is missing menu driven program to delete in linked list attack on titan junior high list of episodes initializer list c++ linked list operations list stl linked list class c++ basic implementation print circular linked list c++ conda list environments how to show list of conda packages reverse a linked list linked list how to reverse a linked list reverse linked list c++ list add

Browse Other Code Languages

CodeProZone