From b0f712fa4a7cb557d1173dd6e37a8f7323a2c0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=A1=E5=9D=82=E6=98=B4?= Date: Thu, 5 Dec 2024 01:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E4=BA=86=E4=BA=9Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homework5/Graph.h | 5 +++-- homework5/GraphExceptions/NodeIdOutOfRangeException.h | 2 +- homework5/GraphExceptions/SameNodeConnectException.h | 2 +- homework5/test1.cpp | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/homework5/Graph.h b/homework5/Graph.h index d3bbf15..318a829 100644 --- a/homework5/Graph.h +++ b/homework5/Graph.h @@ -30,7 +30,7 @@ private: T weight; struct node* next; }; - vector nodes; + vector nodes; int max_size; public: @@ -40,11 +40,12 @@ public: } void insert(T data) { max_size++; - node insert = new node(); + node* insert = new node(); insert->data=max_size; insert->weight = 0; insert->next=new node(); insert->next->data=data; + insert->next->next=NULL; nodes.push_back(insert); } void connect(int id1,int id2,bool flag,T weight=0) { //flag区分是否为有向图 diff --git a/homework5/GraphExceptions/NodeIdOutOfRangeException.h b/homework5/GraphExceptions/NodeIdOutOfRangeException.h index 42c935e..54e18ad 100644 --- a/homework5/GraphExceptions/NodeIdOutOfRangeException.h +++ b/homework5/GraphExceptions/NodeIdOutOfRangeException.h @@ -11,7 +11,7 @@ private: public: NodeIdOutOfRangeException():message("You input id is out of range"){} NodeIdOutOfRangeException(const std::string& msg) : message(msg) {} - NodeIdOutOfRangeException(const std::string& msg,int errCode):message(msg+"Err code: "+std::to_string(errCode)){} + NodeIdOutOfRangeException(const std::string& msg,int errCode):message(msg+" Err code: "+std::to_string(errCode)){} virtual ~NodeIdOutOfRangeException() noexcept {} virtual const char* what() const noexcept override { diff --git a/homework5/GraphExceptions/SameNodeConnectException.h b/homework5/GraphExceptions/SameNodeConnectException.h index 1a5f108..2b155c1 100644 --- a/homework5/GraphExceptions/SameNodeConnectException.h +++ b/homework5/GraphExceptions/SameNodeConnectException.h @@ -12,7 +12,7 @@ private: public: SameNodeConnectException():message("Don't connect same node"){} SameNodeConnectException(const std::string& msg) : message(msg) {} - SameNodeConnectException(const std::string& msg,int errCode):message(msg+"Err code: "+std::to_string(errCode)){} + SameNodeConnectException(const std::string& msg,int errCode):message(msg+" Err code: "+std::to_string(errCode)){} virtual ~SameNodeConnectException() noexcept {} virtual const char* what() const noexcept override { diff --git a/homework5/test1.cpp b/homework5/test1.cpp index 5ada9d0..6b94e4a 100644 --- a/homework5/test1.cpp +++ b/homework5/test1.cpp @@ -25,4 +25,5 @@ using namespace std; int main() { + return 0; }