Implementation Of Graph Using Link List (1)

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Implementation Of Graph Using Link List (1) as PDF for free.

More details

  • Words: 143
  • Pages: 2
Implementation of Graph using Link list #include #include template struct node { T data; node *link; }; template class graph { private: int maxsize; node **first; public: void accept(); void display(); graph(int n) { maxsize=n; first=new node *[maxsize]; } graph(){} }; template void graph::accept() { node *temp,*t; char choice; for(int i=0;i { cout<<"Enter edges for "<<<" Vertex "< t=new node; t->link=NULL; first[i]=t; temp=t; do { int k; cout<<"Enter the Vertex no to which it has to connect :"; cin>>k; if(k { t=new node; t->data=k; t->link=NULL; temp->link=t; temp=temp->link; } else cout<<"Invalid vertex no "< cout<<"Enter another node (Y/N)";

cin>>choice; } while(choice!='n'); node *t1=first[i]; first[i]=first[i]->link; delete(t1); } } template void graph::display() { for(int i=0;i { node *t; t=first[i]; cout<<"Vertex "<<<" is conneted to the vertices "; while(t!=NULL) { coutlink; } cout< } }

void main() { clrscr(); graph g1(5); g1.accept(); g1.display(); getch(); }

Related Documents