SlideShare a Scribd company logo
1 of 10
// This code currently works. Run it and get a screen shot of its
output.
// Next, Convert this code to a class. Have the class in the same
file as the int main.
//please get rid of struct and using :: to covert
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
struct AdjListNode
{
int dest;
struct AdjListNode* next;
};
struct AdjList
{
struct AdjListNode *head;
};
struct Graph
{
int V;
struct AdjList* array;
};
struct AdjListNode * newAdjListNode(int dest)
{
struct AdjListNode * newNode = new AdjListNode;
newNode->dest = dest;
newNode->next = NULL;
return newNode;
}
struct Graph* createGraph(int V)
{
struct Graph* graph = new Graph;
graph->V = V;
graph->array = new AdjList;
int i;
for (i = 0; i < V; ++i)
graph->array[i].head = NULL;
return graph;
}
void addEdge(struct Graph* graph, int src, int dest)
{
struct AdjListNode* newNode = newAdjListNode(dest);
newNode->next = graph->array[src].head;
graph->array[src].head = newNode;
newNode = newAdjListNode(src);
newNode->next = graph->array[dest].head;
graph->array[dest].head = newNode;
}
void printGraph(struct Graph* graph)
{
int v;
for (v = 0; v < graph->V; ++v)
{
struct AdjListNode* pCrawl = graph->array[v].head;
cout << endl << "Adjacency list of vertex " << v <<
endl << " head";
while (pCrawl)
{
cout << "-> " << pCrawl->dest;
pCrawl = pCrawl->next;
}
cout << endl;
}
}
int main()
{
int V = 5;
struct Graph* graph = createGraph(V);
addEdge(graph, 0, 1);
addEdge(graph, 0, 4);
addEdge(graph, 1, 2);
addEdge(graph, 1, 3);
addEdge(graph, 1, 4);
addEdge(graph, 2, 3);
addEdge(graph, 3, 4);
printGraph(graph);
system("pause");
return 0;
}
Solution
With using struct:
program:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
struct AdjListNode
{
int dest;
struct AdjListNode* next;
};
struct AdjList
{
struct AdjListNode *head;
};
struct Graph
{
int V;
struct AdjList* array;
};
struct AdjListNode * newAdjListNode(int dest)
{
struct AdjListNode * newNode = new AdjListNode;
newNode->dest = dest;
newNode->next = NULL;
return newNode;
}
struct Graph* createGraph(int V)
{
struct Graph* graph = new Graph;
graph->V = V;
graph->array = new AdjList;
int i;
for (i = 0; i < V; ++i)
graph->array[i].head = NULL;
return graph;
}
void addEdge(struct Graph* graph, int src, int dest)
{
struct AdjListNode* newNode = newAdjListNode(dest);
newNode->next = graph->array[src].head;
graph->array[src].head = newNode;
newNode = newAdjListNode(src);
newNode->next = graph->array[dest].head;
graph->array[dest].head = newNode;
}
void printGraph(struct Graph* graph)
{
int v;
for (v = 0; v < graph->V; ++v)
{
struct AdjListNode* pCrawl = graph->array[v].head;
cout << endl << "Adjacency list of vertex " << v <<
endl << " head";
while (pCrawl)
{
cout << "-> " << pCrawl->dest;
pCrawl = pCrawl->next;
}
cout << endl;
}
}
int main()
{
int V = 5;
struct Graph* graph = createGraph(V);
addEdge(graph, 0, 1);
addEdge(graph, 0, 4);
addEdge(graph, 1, 2);
addEdge(graph, 1, 3);
addEdge(graph, 1, 4);
addEdge(graph, 2, 3);
addEdge(graph, 3, 4);
printGraph(graph);
system("pause");
return 0;
}
Using Classes:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class AdjListNode
{
public:
int dest;
AdjListNode* next;
};
class AdjList
{
public:
AdjListNode *head;
};
class Graph
{
public:
int V;
AdjList* array;
};
AdjListNode* newAdjListNode(int dest)
{
AdjListNode * newNode = new AdjListNode;
newNode->dest = dest;
newNode->next = NULL;
return newNode;
}
Graph* createGraph(int V)
{
Graph* graph = new Graph;
graph->V = V;
graph->array = new AdjList;
int i;
for (i = 0; i < V; ++i)
graph->array[i].head = NULL;
return graph;
}
void addEdge(Graph* graph, int src, int dest)
{
AdjListNode* newNode = newAdjListNode(dest);
newNode->next = graph->array[src].head;
graph->array[src].head = newNode;
newNode = newAdjListNode(src);
newNode->next = graph->array[dest].head;
graph->array[dest].head = newNode;
}
void printGraph(Graph* graph)
{
int v;
for (v = 0; v < graph->V; ++v)
{
AdjListNode* pCrawl = graph->array[v].head;
cout << endl << "Adjacency list of vertex " << v << endl <<
" head";
while (pCrawl)
{
cout << "-> " << pCrawl->dest;
pCrawl = pCrawl->next;
}
cout << endl;
}
}
int main()
{
int V = 5;
Graph* graph = createGraph(V);
addEdge(graph, 0, 1);
addEdge(graph, 0, 4);
addEdge(graph, 1, 2);
addEdge(graph, 1, 3);
addEdge(graph, 1, 4);
addEdge(graph, 2, 3);
addEdge(graph, 3, 4);
printGraph(graph);
system("pause");
return 0;
}

More Related Content

Similar to This code currently works. Run it and get a screen shot of its ou.docx

DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfaathiauto
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfSANDEEPARIHANT
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfalphaagenciesindia
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfsales88
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docxajoy21
 
Write a program that reads a graph from a file and determines whether.docx
 Write a program that reads a graph from a file and determines whether.docx Write a program that reads a graph from a file and determines whether.docx
Write a program that reads a graph from a file and determines whether.docxajoy21
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
Complete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfComplete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfmarketing413921
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdfadityastores21
 
Most Important C language program
Most Important C language programMost Important C language program
Most Important C language programTEJVEER SINGH
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxteyaj1
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
 

Similar to This code currently works. Run it and get a screen shot of its ou.docx (20)

DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdf
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
 
C++ programs
C++ programsC++ programs
C++ programs
 
Write a program that reads a graph from a file and determines whether.docx
 Write a program that reads a graph from a file and determines whether.docx Write a program that reads a graph from a file and determines whether.docx
Write a program that reads a graph from a file and determines whether.docx
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Day 1
Day 1Day 1
Day 1
 
Complete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfComplete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdf
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
C program
C programC program
C program
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
Most Important C language program
Most Important C language programMost Important C language program
Most Important C language program
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
 

More from Komlin1

Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docxTheodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docxKomlin1
 
Theory and Research Related to Social Issue By now, you have had t.docx
Theory and Research Related to Social Issue By now, you have had t.docxTheory and Research Related to Social Issue By now, you have had t.docx
Theory and Research Related to Social Issue By now, you have had t.docxKomlin1
 
Theory and the White-Collar OffenderOur previous week’s discussion.docx
Theory and the White-Collar OffenderOur previous week’s discussion.docxTheory and the White-Collar OffenderOur previous week’s discussion.docx
Theory and the White-Collar OffenderOur previous week’s discussion.docxKomlin1
 
There are 2 questions part A and B. All questions and relevant att.docx
There are 2 questions part A and B. All questions and relevant att.docxThere are 2 questions part A and B. All questions and relevant att.docx
There are 2 questions part A and B. All questions and relevant att.docxKomlin1
 
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docxThere are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docxKomlin1
 
Theoretical PerspectiveIdentify at least one human developme.docx
Theoretical PerspectiveIdentify at least one human developme.docxTheoretical PerspectiveIdentify at least one human developme.docx
Theoretical PerspectiveIdentify at least one human developme.docxKomlin1
 
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docxTHEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docxKomlin1
 
Theories of Behavior TimelineComplete the following tabl.docx
Theories of Behavior TimelineComplete the following tabl.docxTheories of Behavior TimelineComplete the following tabl.docx
Theories of Behavior TimelineComplete the following tabl.docxKomlin1
 
Thematic Issues Globalization; Islam & the West.docx
Thematic Issues Globalization; Islam & the West.docxThematic Issues Globalization; Islam & the West.docx
Thematic Issues Globalization; Islam & the West.docxKomlin1
 
The written portion of the research paper should be 9-11 pages in le.docx
The written portion of the research paper should be 9-11 pages in le.docxThe written portion of the research paper should be 9-11 pages in le.docx
The written portion of the research paper should be 9-11 pages in le.docxKomlin1
 
The World since 1945Country Report- SAUDI ARABIA     Histo.docx
The World since 1945Country Report- SAUDI ARABIA     Histo.docxThe World since 1945Country Report- SAUDI ARABIA     Histo.docx
The World since 1945Country Report- SAUDI ARABIA     Histo.docxKomlin1
 
The world runs on Big Data.  Traditionally, Data has been expressed .docx
The world runs on Big Data.  Traditionally, Data has been expressed .docxThe world runs on Big Data.  Traditionally, Data has been expressed .docx
The world runs on Big Data.  Traditionally, Data has been expressed .docxKomlin1
 
the    1.The collaborative planning Methodology is the f.docx
the    1.The collaborative planning Methodology is the f.docxthe    1.The collaborative planning Methodology is the f.docx
the    1.The collaborative planning Methodology is the f.docxKomlin1
 
The word stereotype originally referred to a method used by printers.docx
The word stereotype originally referred to a method used by printers.docxThe word stereotype originally referred to a method used by printers.docx
The word stereotype originally referred to a method used by printers.docxKomlin1
 
The Value of Critical Thinking  Please respond to the followin.docx
The Value of Critical Thinking  Please respond to the followin.docxThe Value of Critical Thinking  Please respond to the followin.docx
The Value of Critical Thinking  Please respond to the followin.docxKomlin1
 
The Value Chain Concept Please respond to the following·.docx
The Value Chain Concept Please respond to the following·.docxThe Value Chain Concept Please respond to the following·.docx
The Value Chain Concept Please respond to the following·.docxKomlin1
 
The wealth and energy between 1880 and 1910 was a unique and dynamic.docx
The wealth and energy between 1880 and 1910 was a unique and dynamic.docxThe wealth and energy between 1880 and 1910 was a unique and dynamic.docx
The wealth and energy between 1880 and 1910 was a unique and dynamic.docxKomlin1
 
The Value of Research in Social PolicyWhile research can be intere.docx
The Value of Research in Social PolicyWhile research can be intere.docxThe Value of Research in Social PolicyWhile research can be intere.docx
The Value of Research in Social PolicyWhile research can be intere.docxKomlin1
 
The United States’ foreign policy until the end of the nineteenth ce.docx
The United States’ foreign policy until the end of the nineteenth ce.docxThe United States’ foreign policy until the end of the nineteenth ce.docx
The United States’ foreign policy until the end of the nineteenth ce.docxKomlin1
 
The Value Chain Concept Please respond to the followingDescribe.docx
The Value Chain Concept Please respond to the followingDescribe.docxThe Value Chain Concept Please respond to the followingDescribe.docx
The Value Chain Concept Please respond to the followingDescribe.docxKomlin1
 

More from Komlin1 (20)

Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docxTheodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
Theodore Robert (Ted) BundyReview the case of Theodore Robert (Ted.docx
 
Theory and Research Related to Social Issue By now, you have had t.docx
Theory and Research Related to Social Issue By now, you have had t.docxTheory and Research Related to Social Issue By now, you have had t.docx
Theory and Research Related to Social Issue By now, you have had t.docx
 
Theory and the White-Collar OffenderOur previous week’s discussion.docx
Theory and the White-Collar OffenderOur previous week’s discussion.docxTheory and the White-Collar OffenderOur previous week’s discussion.docx
Theory and the White-Collar OffenderOur previous week’s discussion.docx
 
There are 2 questions part A and B. All questions and relevant att.docx
There are 2 questions part A and B. All questions and relevant att.docxThere are 2 questions part A and B. All questions and relevant att.docx
There are 2 questions part A and B. All questions and relevant att.docx
 
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docxThere are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
There are 2 discussions Topic 1 & Topic 2 (They both require refere.docx
 
Theoretical PerspectiveIdentify at least one human developme.docx
Theoretical PerspectiveIdentify at least one human developme.docxTheoretical PerspectiveIdentify at least one human developme.docx
Theoretical PerspectiveIdentify at least one human developme.docx
 
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docxTHEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
THEIEPGOALSSHOULD BE WRITTEN INAWORDDO.docx
 
Theories of Behavior TimelineComplete the following tabl.docx
Theories of Behavior TimelineComplete the following tabl.docxTheories of Behavior TimelineComplete the following tabl.docx
Theories of Behavior TimelineComplete the following tabl.docx
 
Thematic Issues Globalization; Islam & the West.docx
Thematic Issues Globalization; Islam & the West.docxThematic Issues Globalization; Islam & the West.docx
Thematic Issues Globalization; Islam & the West.docx
 
The written portion of the research paper should be 9-11 pages in le.docx
The written portion of the research paper should be 9-11 pages in le.docxThe written portion of the research paper should be 9-11 pages in le.docx
The written portion of the research paper should be 9-11 pages in le.docx
 
The World since 1945Country Report- SAUDI ARABIA     Histo.docx
The World since 1945Country Report- SAUDI ARABIA     Histo.docxThe World since 1945Country Report- SAUDI ARABIA     Histo.docx
The World since 1945Country Report- SAUDI ARABIA     Histo.docx
 
The world runs on Big Data.  Traditionally, Data has been expressed .docx
The world runs on Big Data.  Traditionally, Data has been expressed .docxThe world runs on Big Data.  Traditionally, Data has been expressed .docx
The world runs on Big Data.  Traditionally, Data has been expressed .docx
 
the    1.The collaborative planning Methodology is the f.docx
the    1.The collaborative planning Methodology is the f.docxthe    1.The collaborative planning Methodology is the f.docx
the    1.The collaborative planning Methodology is the f.docx
 
The word stereotype originally referred to a method used by printers.docx
The word stereotype originally referred to a method used by printers.docxThe word stereotype originally referred to a method used by printers.docx
The word stereotype originally referred to a method used by printers.docx
 
The Value of Critical Thinking  Please respond to the followin.docx
The Value of Critical Thinking  Please respond to the followin.docxThe Value of Critical Thinking  Please respond to the followin.docx
The Value of Critical Thinking  Please respond to the followin.docx
 
The Value Chain Concept Please respond to the following·.docx
The Value Chain Concept Please respond to the following·.docxThe Value Chain Concept Please respond to the following·.docx
The Value Chain Concept Please respond to the following·.docx
 
The wealth and energy between 1880 and 1910 was a unique and dynamic.docx
The wealth and energy between 1880 and 1910 was a unique and dynamic.docxThe wealth and energy between 1880 and 1910 was a unique and dynamic.docx
The wealth and energy between 1880 and 1910 was a unique and dynamic.docx
 
The Value of Research in Social PolicyWhile research can be intere.docx
The Value of Research in Social PolicyWhile research can be intere.docxThe Value of Research in Social PolicyWhile research can be intere.docx
The Value of Research in Social PolicyWhile research can be intere.docx
 
The United States’ foreign policy until the end of the nineteenth ce.docx
The United States’ foreign policy until the end of the nineteenth ce.docxThe United States’ foreign policy until the end of the nineteenth ce.docx
The United States’ foreign policy until the end of the nineteenth ce.docx
 
The Value Chain Concept Please respond to the followingDescribe.docx
The Value Chain Concept Please respond to the followingDescribe.docxThe Value Chain Concept Please respond to the followingDescribe.docx
The Value Chain Concept Please respond to the followingDescribe.docx
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

This code currently works. Run it and get a screen shot of its ou.docx

  • 1. // This code currently works. Run it and get a screen shot of its output. // Next, Convert this code to a class. Have the class in the same file as the int main. //please get rid of struct and using :: to covert #include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; struct AdjListNode { int dest; struct AdjListNode* next; }; struct AdjList { struct AdjListNode *head; }; struct Graph { int V; struct AdjList* array; }; struct AdjListNode * newAdjListNode(int dest) { struct AdjListNode * newNode = new AdjListNode; newNode->dest = dest; newNode->next = NULL; return newNode; }
  • 2. struct Graph* createGraph(int V) { struct Graph* graph = new Graph; graph->V = V; graph->array = new AdjList; int i; for (i = 0; i < V; ++i) graph->array[i].head = NULL; return graph; } void addEdge(struct Graph* graph, int src, int dest) { struct AdjListNode* newNode = newAdjListNode(dest); newNode->next = graph->array[src].head; graph->array[src].head = newNode; newNode = newAdjListNode(src); newNode->next = graph->array[dest].head; graph->array[dest].head = newNode; } void printGraph(struct Graph* graph) { int v; for (v = 0; v < graph->V; ++v) { struct AdjListNode* pCrawl = graph->array[v].head; cout << endl << "Adjacency list of vertex " << v << endl << " head"; while (pCrawl) {
  • 3. cout << "-> " << pCrawl->dest; pCrawl = pCrawl->next; } cout << endl; } } int main() { int V = 5; struct Graph* graph = createGraph(V); addEdge(graph, 0, 1); addEdge(graph, 0, 4); addEdge(graph, 1, 2); addEdge(graph, 1, 3); addEdge(graph, 1, 4); addEdge(graph, 2, 3); addEdge(graph, 3, 4); printGraph(graph); system("pause"); return 0; } Solution With using struct: program: #include "stdafx.h"
  • 4. #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; struct AdjListNode { int dest; struct AdjListNode* next; }; struct AdjList { struct AdjListNode *head; }; struct Graph { int V; struct AdjList* array; }; struct AdjListNode * newAdjListNode(int dest) { struct AdjListNode * newNode = new AdjListNode;
  • 5. newNode->dest = dest; newNode->next = NULL; return newNode; } struct Graph* createGraph(int V) { struct Graph* graph = new Graph; graph->V = V; graph->array = new AdjList; int i; for (i = 0; i < V; ++i) graph->array[i].head = NULL; return graph; } void addEdge(struct Graph* graph, int src, int dest) { struct AdjListNode* newNode = newAdjListNode(dest); newNode->next = graph->array[src].head; graph->array[src].head = newNode;
  • 6. newNode = newAdjListNode(src); newNode->next = graph->array[dest].head; graph->array[dest].head = newNode; } void printGraph(struct Graph* graph) { int v; for (v = 0; v < graph->V; ++v) { struct AdjListNode* pCrawl = graph->array[v].head; cout << endl << "Adjacency list of vertex " << v << endl << " head"; while (pCrawl) { cout << "-> " << pCrawl->dest; pCrawl = pCrawl->next; } cout << endl; } } int main() { int V = 5;
  • 7. struct Graph* graph = createGraph(V); addEdge(graph, 0, 1); addEdge(graph, 0, 4); addEdge(graph, 1, 2); addEdge(graph, 1, 3); addEdge(graph, 1, 4); addEdge(graph, 2, 3); addEdge(graph, 3, 4); printGraph(graph); system("pause"); return 0; } Using Classes: #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; class AdjListNode { public: int dest; AdjListNode* next; };
  • 8. class AdjList { public: AdjListNode *head; }; class Graph { public: int V; AdjList* array; }; AdjListNode* newAdjListNode(int dest) { AdjListNode * newNode = new AdjListNode; newNode->dest = dest; newNode->next = NULL; return newNode; } Graph* createGraph(int V) { Graph* graph = new Graph; graph->V = V; graph->array = new AdjList;
  • 9. int i; for (i = 0; i < V; ++i) graph->array[i].head = NULL; return graph; } void addEdge(Graph* graph, int src, int dest) { AdjListNode* newNode = newAdjListNode(dest); newNode->next = graph->array[src].head; graph->array[src].head = newNode; newNode = newAdjListNode(src); newNode->next = graph->array[dest].head; graph->array[dest].head = newNode; } void printGraph(Graph* graph) { int v; for (v = 0; v < graph->V; ++v) { AdjListNode* pCrawl = graph->array[v].head; cout << endl << "Adjacency list of vertex " << v << endl << " head"; while (pCrawl) { cout << "-> " << pCrawl->dest;
  • 10. pCrawl = pCrawl->next; } cout << endl; } } int main() { int V = 5; Graph* graph = createGraph(V); addEdge(graph, 0, 1); addEdge(graph, 0, 4); addEdge(graph, 1, 2); addEdge(graph, 1, 3); addEdge(graph, 1, 4); addEdge(graph, 2, 3); addEdge(graph, 3, 4); printGraph(graph); system("pause"); return 0; }