Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please code this in c++ Create a function to display the entire adjacency list t

ID: 3756687 • Letter: P

Question

Please code this in c++

Create a function to display the entire adjacency list to the screen. See the example dialog on how
adjList should be output to the screen. You decide on the prototype and if it is invoked for each
list in the adjacency list or do you pass in a reference to the adjList

Here is an example of what the ajacency list would look like:
// if adjList is printed, output is
list0 0 1 2 5 6
list1 0 1
list2 0 2
list3 3 4 5
list4 3 4 5 6
list5 0 3 4 5
list6 0 4 6
list7 7 8
list8 7 8
list9 9 10 11 12
list10 9 10
list11 9 11 12
list12 9 11 12

!!(DONT worry to much about the list #'s I care about getting the values from 0 1 2 5 6 to 0 1 in the next)!!

given adjacency list code:

#include
#include
#include

using std::cout;
using std::endl;
using std::cin;
using std::list;
using std::vector;

int main()
{
vector > adjList;
list mtLst; // an empty list

for (int i=0; i<4; ++i)
{
adjList.push_back(mtLst); // push an empty list onto the adjList
for (int j=0; j<=i; ++j)
adjList[i].push_back(j); // populate the list just pushed onto the vector

}

return 0;
}

Explanation / Answer

// I am submit your code in simple way so you can understood in simply it give output as you want.

#include <iostream>
#include <list>
#include <iterator>
#include<vector>
using namespace std;
void print(vector<int>printlist,int i)//i is the index of each lists in adjList;;
{
int j;
cout<<"list"<<i<<" ";
int l=printlist.size();
for(j=0;j<l;j++)
{
cout<<printlist[j]<<" ";
}
cout<<endl;
}
int main()
{
vector<int>adjList;//declare vector (adjList) whilch contain lists;
for (int i=0; i<4;i++)
{
for (int j=0; j<=i; j++)
adjList.push_back(j);// populate the list just pushed onto the vector
print(adjList,i);//just pass vector (adjList) to a function print and index of lists are i;
adjList.clear();//now clear previous vector so we can consider it's as empty for next time when we use;
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote