title: Aborted(core dumped)
body: <p>I write a program about graph(in Data Structure), when I finish coding, I compiled it successfullly, but when I run the .out file, it turns out these</p>
  
  <pre><code>razrlele@razrlele-ThinkPad:~/work/ds$ ./graph
  graph: malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &amp;((av)-       &gt;bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) &amp;&amp; old_size == 0) || ((unsigned long) (old_size) &gt;= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1)) &amp; ~((2 *(sizeof(size_t))) - 1))) &amp;&amp; ((old_top)-&gt;size &amp; 0x1) &amp;&amp; ((unsigned long) old_end &amp; pagemask) == 0)' failed.
  Aborted (core dumped)
  </code></pre>
  
  <p>I have never encouter this kind of error, how can I deal with it?
  Here is my codes:</p>
  
  <pre><code>    #include &lt;iostream&gt;
  using namespace std;
  #include &lt;stdlib.h&gt;
  #define MAX 20
  
  typedef struct graph
  {
      char v[MAX+1]; //the mark of each vertex
      int vexnum, arcnum; //the number of vertex and arc
      int w[MAX+1][MAX+1]; //matrix with weight of each arc
  }*wgraph;
  
  typedef struct stack
  {
      char v[MAX+1];
      int len;
  }*wstack; //stack used to calculate the path
  wstack sc;
  wstack way;
  void creategraph(wgraph &amp;M);
  void build(wstack &amp;s);
  void clear(wstack &amp;s);
  
  void push(wstack &amp;s, char e);
  char pop(wstack &amp;s);
  int locate(wgraph M, char e);
  int In(wstack s, char e);
  
  void show(wgraph M, wstack s);
  int compute(wgraph M, wstack s);
  void compare(wgraph M, wstack &amp;s1, wstack &amp;s2);
  void calculate(wgraph &amp;M, int i, int j);
  
  int main()
  {
      char a,b;
      int key;
      wgraph M;
  
      build(sc);
      build(way);
      creategraph(M);
      while(1)
      {
          clear(sc);
          clear(way);
          cout&lt;&lt;"What would you like?"&lt;&lt;endl
              &lt;&lt;"1. Find a best path"&lt;&lt;endl
              &lt;&lt;"0. Exit"&lt;&lt;endl;
          cin&gt;&gt;key;
          switch(key)
          {
              case 1:
                  cout&lt;&lt;"Please input two vertexs:"&lt;&lt;endl;
                  cin&gt;&gt;a&gt;&gt;b;
                  calculate(M, locate(M, a), locate(M, b));
                  break;
              case 0:
                  cout&lt;&lt;"Thank you, ByeBye!";
                  return 0;
          }
      return 0;
      }
  }
  
  void creategraph(wgraph &amp;M)
  {
      int i, j, weight ;
      char p1, p2;
      M = (wgraph )malloc(sizeof(wgraph));
      cout&lt;&lt;"Please input the number of vertex and arc"&lt;&lt;endl;
      cin&gt;&gt;M-&gt;vexnum&gt;&gt;M-&gt;arcnum;
      for(i = 1; i &lt;= M-&gt;vexnum; i++)
       for(j = 1; j &lt;= M-&gt;vexnum; j++)
       {
          if(i == j) M-&gt;w[i][j] = 0;
          else M-&gt;w[i][j] = -1;
      } // initiate the matrix
      cout&lt;&lt;"Vertex: "&lt;&lt;M-&gt;vexnum&lt;&lt;" Arc: "&lt;&lt;M-&gt;arcnum&lt;&lt;endl;
      cout&lt;&lt;"PLease input the mark of each vertex"&lt;&lt;endl;
      for(i = 1; i &lt;= M-&gt;vexnum; i++)
          cin&gt;&gt;M-&gt;v[i];
      for(i = 1; i &lt;= M-&gt;vexnum; i++)
          cout&lt;&lt;M-&gt;v[i];
      cout&lt;&lt;endl&lt;&lt;"please in put each arc like: a b 4"&lt;&lt;endl;
      for(i = 1; i &lt;= M-&gt;arcnum; i++)
      {
          cout&lt;&lt;"Please input the "&lt;&lt;i&lt;&lt;" data"&lt;&lt;endl;
          cin&gt;&gt;p1&gt;&gt;p2;
          M-&gt;w[locate(M, p1)][locate(M, p2)] = weight;
          M-&gt;w[locate(M, p2)][locate(M, p1)] = weight;
      }
  }//creategraph
  
  void build(wstack &amp;s)
  {
      s = (wstack )malloc(sizeof(wstack));
      s-&gt;len = 0;
  }//build
  
  void clear(wstack &amp;s)
  {
      int i;
      for(i = 1; i &lt;= s-&gt;len; i++)
      s-&gt;v[i] = '\0';
      s-&gt;len = 0;
  }//clear
  
  void push(wstack &amp;s, char e)
  {
      if(s-&gt;len &lt;= MAX)
      s-&gt;v[++s-&gt;len] = e;
  }//push
  
  char pop(wstack &amp;s)
  {
      if(s-&gt;len &gt; 0)
      return s-&gt;v[s-&gt;len--];
      return 0;
  }//pop
  
  int locate(wgraph M, char e) //locate the position of each vertex 
  {
      int i;
      for(i = 1; i &lt;= M-&gt;vexnum; i++)
      if( e == M-&gt;v[i]) return i;
  }
  int In(wstack s, char e)
  {
      int i;
      for(i = 1; i &lt;= s-&gt;len; i++)
      if (s-&gt;v[i] == e) return 1;
      return 0;
  }//In
  
  void show(wgraph M, wstack s)
  {
      int i;
      for(i = 1; i&lt;=s-&gt;len; i++)
          cout&lt;&lt;s-&gt;v[i];
      cout&lt;&lt;'\t'&lt;&lt;compute(M, s)&lt;&lt;endl;
  }//show
  
  int compute(wgraph M, wstack s)
  {
      int sum = 0, i;
      for(i = 1; i &lt; s-&gt;len; i++)
      sum += M-&gt;w[locate(M, s-&gt;v[i])][locate(M, s-&gt;v[i+1])];
      return sum;
  }//compute
  
  void compare(wgraph M, wstack &amp;s1, wstack &amp;s2)
  {
      int i;
      if(compute(M, s2) == 0 || compute(M, s2) &gt; compute(M, s1))
      for(i = 1; i &lt;= s1-&gt;len; i++)
      s2-&gt;v[i] = s1-&gt;v[i];
      s2-&gt;len = s2-&gt;len;
  }//compare
  
  void calculate(wgraph &amp;M, int i, int j)
  {
      int k;
      push(sc, M-&gt;v[i]);
      for(k = 0; k &lt; M-&gt;vexnum; k++)
      {
      if((In(sc, M-&gt;v[k]) &amp;&amp; k != j|| M-&gt;w[i][k] &lt;= 0))
       continue; // skip two points where there is no arch
              else if(k != j)
              calculate(M, k, j);
              else if(k == j &amp;&amp; sc-&gt;len == M-&gt;vexnum)
                  {
                  push(sc, M-&gt;v[k]);
                  show(M, sc);
                  compare(M, sc, way);
                  pop(sc);
                  }
      }
      pop(sc);
  }
  </code></pre>