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

I can compile but everytime i enter the text doc i get a segment fault error and

ID: 3555955 • Letter: I

Question

I can compile but everytime i enter the text doc i get a segment fault error and i cannot find the issue. I know that is in the createGraph function.

Task:
Write a program that will create a graph by reading data from
lab10.txt and output the nodes of the graph in depth-first and
breadth-first traversal.
Design your output (to lab10.out) to be pleasing and informative

#ifndef H_graph
#define H_graph

//***************************************************************
// Author: D.S. Malik
//
// class graphType
// This class specifies the basic operations to implement a graph.
//****************************************************************

#include
#include
#include
#include "linkedList.h"
#include "unorderedLinkedList.h"
#include "linkedQueue.h"

using namespace std;

class graphType
{
public:
bool isEmpty() const;
//Function to determine whether the graph is empty.
//Postcondition: Returns true if the graph is empty;
// otherwise, returns false.

void createGraph();
//Function to create a graph.
//Postcondition: The graph is created using the
// adjacency list representation.

void clearGraph();
//Function to clear graph.
//Postcondition: The memory occupied by each vertex
// is deallocated.

void printGraph() const;
//Function to print graph.
//Postcondition: The graph is printed.

void depthFirstTraversal();
//Function to perform the depth first traversal of
//the entire graph.
//Postcondition: The vertices of the graph are printed
// using the depth first traversal algorithm.

void dftAtVertex(int vertex);
//Function to perform the depth first traversal of
//the graph at a node specified by the parameter vertex.
//Postcondition: Starting at vertex, the vertices are
// printed using the depth first traversal algorithm.

void breadthFirstTraversal();
//Function to perform the breadth first traversal of
//the entire graph.
//Postcondition: The vertices of the graph are printed
// using the breadth first traversal algorithm.

graphType(int size = 0);
//Constructor
//Postcondition: gSize = 0; maxSize = size;
// graph is an array of pointers to linked lists.

~graphType();
//Destructor
//The storage occupied by the vertices is deallocated.

protected:
int maxSize; //maximum number of vertices
int gSize; //current number of vertices
unorderedLinkedList *graph; //array to create
//adjacency lists

private:
void dft(int v, bool visited[]);
//Function to perform the depth first traversal of
//the graph at a node specified by the parameter vertex.
//This function is used by the public member functions
//depthFirstTraversal and dftAtVertex.
//Postcondition: Starting at vertex, the vertices are
// printed using the depth first traversal algorithm.
};

lab10.txt output:

11
0 1 5 -999
1 2 3 5 -999
2 4 -999
3 -999
4 3 -999
5 6 -999
6 8 -999
7 3 8 -999
8 10 -999
9 4 7 10 -999
10 -999

Explanation / Answer

b)Program to implement Depth First Search Algorithm.

  #include<iostream.h>  #include<conio.h>  #include<stdlib.h>  int cost[10][10],i,j,k,n,queue[10],front,rear,v,visit[10],visited[10];  void main()  {          int m;          clrscr();          cout <<"enterno of vertices";          cin >> n;          cout <<"ente no of edges";          cin >> m;          cout <<" EDGES  ";          for(k=1;k<=m;k++)          {                  cin >>i>>j;                  cost[i][j]=1;          }          cout <<"enter initial vertex";          cin >>v;          cout <<"Visitied vertices ";          cout << v;          visited[v]=1;          k=1;          while(k<n)          {                  for(j=1;j<=n;j++)                          if(cost[v][j]!=0 && visited[j]!=1 && visit[j]!=1)                          {                                  visit[j]=1;                                  queue[rear++]=j;                          }                  v=queue[front++];                  cout<<v << " ";                  k++;                  visit[v]=0;                  visited[v]=1;          }          getch();  }  
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