{"id":52831,"date":"2009-04-14T00:02:00","date_gmt":"2009-04-14T00:02:00","guid":{"rendered":"\/2009\/04\/14\/ece231-spring-2009-programming-assignment-4"},"modified":"2009-08-30T00:16:38","modified_gmt":"2009-08-30T00:16:38","slug":"ece231-spring-2009-programming-assignment-4","status":"publish","type":"post","link":"http:\/\/pullmonkey.com\/2009\/04\/14\/ece231-spring-2009-programming-assignment-4\/","title":{"rendered":"ECE231 – Spring 2009 – Programming Assignment 4"},"content":{"rendered":"

This is a step-by-step tutorial for this assignment and an explanation of the basics of how it works for those that are having a difficult time understanding or just are stuck somewhere. To view the assignment click here<\/a>.<\/p>\n

So for this assignment we are only going to be doing input and output. So the only header file we need is the iostream<\/b> library.<\/p>\n\n\n
\n
1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt><\/pre>\n<\/td>\n
\n
\n<\/tt>#include<\/span> <iostream><\/span>\n<\/tt>using namespace std;\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

Defining the Node Class<\/h2>\n

For the node<\/b> class we need 5 private variables: type<\/i><\/b>, value<\/i><\/b>, node1<\/i><\/b>, node2<\/i><\/b>, next<\/i><\/b>, a constructor<\/b>, 5 member functions<\/b>, and a friend class<\/b>.<\/p>\n

Because most of the functions only return a single variable it would be a waste to have the functions outside the class so I put them all inside the class.<\/p>\n

So here is what your class should look like:<\/p>\n\n\n
\n
1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt>23\n<\/tt>24\n<\/tt>25<\/strong>\n<\/tt>26\n<\/tt>27\n<\/tt><\/pre>\n<\/td>\n
\n
\n<\/tt>class node\n<\/tt>{\n<\/tt>  protected:<\/span>\n<\/tt>    int<\/span> type;     \/\/ type of component<\/span>\n<\/tt>    double<\/span> value; \/\/ value of the component<\/span>\n<\/tt>    int<\/span> node1;    \/\/ first node of the component<\/span>\n<\/tt>    int<\/span> node2;    \/\/ second node of the component<\/span>\n<\/tt>    node *next;   \/\/ pointer to the next node in list<\/span>\n<\/tt>  public:<\/span>\n<\/tt>    node(int<\/span> a, double<\/span> b, int<\/span> c, int<\/span> d)\n<\/tt>    {\n<\/tt>      type  = a;\n<\/tt>      value = b;\n<\/tt>      node1 = c;\n<\/tt>      node2 = d;\n<\/tt>    }\n<\/tt>\n<\/tt>    int<\/span> getType() { return<\/span> type; }\n<\/tt>    double<\/span> getValue() { return<\/span> value; }\n<\/tt>    int<\/span> getNode1() { return<\/span> node1; }\n<\/tt>    int<\/span> getNode2() { return<\/span> node2; }\n<\/tt>    node *getNext() { return<\/span> next; }\n<\/tt>\n<\/tt>    friend class circuit;\n<\/tt>};\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

Defining the Circuit Class<\/h2>\n

For the circuit<\/b> class we need 2 private variables: first<\/i><\/b> and last<\/i><\/b>, a constructor<\/b>, a copy constructor<\/b>, 6 member functions<\/b>, and a friend function<\/b>.<\/p>\n

For these I will put most of the functions on the outside of the class.<\/p>\n

So here is what your class should look like:<\/p>\n\n\n
\n
1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt><\/pre>\n<\/td>\n
\n
\n<\/tt>class circuit\n<\/tt>{\n<\/tt>  protected:<\/span>\n<\/tt>    node *first; \/\/ pointer to first node in list<\/span>\n<\/tt>    node *last;  \/\/ pointer to last node in list<\/span>\n<\/tt>    node *getNode(int<\/span> & , double<\/span> & , int<\/span> & , int<\/span> & );\n<\/tt>  public:<\/span>\n<\/tt>    circuit();\n<\/tt>    circuit(const<\/span> circuit & );\n<\/tt>    ~circuit();\n<\/tt>\n<\/tt>    void<\/span> insert(int<\/span> , double<\/span> , int<\/span> , int<\/span> );\n<\/tt>    void<\/span> insertInFront(node * );\n<\/tt>    void<\/span> insertInBack(node * , node * );\n<\/tt>    void<\/span> insertInMiddle(node * , node * , node * );\n<\/tt>    bool<\/span> remove(int<\/span> , int<\/span> );\n<\/tt>    bool<\/span> isEmpty();\n<\/tt>\n<\/tt>    friend ostream & operator << (ostream & , circuit );\n<\/tt>};\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

Writing the Actual Functions for the Circuit Class<\/h2>\n

First, we have the private function getNode<\/b>. This function creates a new member of the node<\/b> class and returns the address to it.<\/p>\n\n\n
\n
1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt><\/pre>\n<\/td>\n
\n
\n<\/tt>node* circuit::getNode(int<\/span> &t, double<\/span> &v, int<\/span> &n1, int<\/span> &n2)\n<\/tt>{\n<\/tt>  node *temp = new node(t, v, n1, n2);\n<\/tt>  assert( temp != 0<\/span> );\n<\/tt>  return<\/span> temp;\n<\/tt>}\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

Second, we have the a constructor<\/b>, a copy constructor<\/b>, and a class destructor<\/b>:<\/p>\n\n\n
\n
1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt>23\n<\/tt>24\n<\/tt>25<\/strong>\n<\/tt>26\n<\/tt>27\n<\/tt>28\n<\/tt>29\n<\/tt>30<\/strong>\n<\/tt><\/pre>\n<\/td>\n
\n
\n<\/tt>circuit::circuit()\n<\/tt>{\n<\/tt>  first = last = 0<\/span>;\n<\/tt>}\n<\/tt>circuit::circuit(const<\/span> circuit &c)\n<\/tt>{\n<\/tt>  first = last = 0<\/span>;\n<\/tt>  node *nc = c.first;\n<\/tt>  while<\/span>(nc != 0<\/span>)\n<\/tt>  {\n<\/tt>    insert(nc->type, nc->value, nc->node1, nc->node2);\n<\/tt>    nc = nc->next;\n<\/tt>  }\n<\/tt>}\n<\/tt>circuit::~circuit()\n<\/tt>{\n<\/tt>  if<\/span>( !isEmpty() )\n<\/tt>  {\n<\/tt>    node *nc = first;\n<\/tt>    node *temp;\n<\/tt>    while<\/span>(nc != 0<\/span>)\n<\/tt>    {\n<\/tt>      temp = nc;\n<\/tt>      nc = nc->next;\n<\/tt>      delete temp;\n<\/tt>    }\n<\/tt>  }\n<\/tt>}\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

Next, we have the 6 member functions<\/b>:<\/p>\n\n\n
\n
1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt>23\n<\/tt>24\n<\/tt>25<\/strong>\n<\/tt>26\n<\/tt>27\n<\/tt>28\n<\/tt>29\n<\/tt>30<\/strong>\n<\/tt>31\n<\/tt>32\n<\/tt>33\n<\/tt>34\n<\/tt>35<\/strong>\n<\/tt>36\n<\/tt>37\n<\/tt>38\n<\/tt>39\n<\/tt>40<\/strong>\n<\/tt>41\n<\/tt>42\n<\/tt>43\n<\/tt>44\n<\/tt>45<\/strong>\n<\/tt>46\n<\/tt>47\n<\/tt>48\n<\/tt>49\n<\/tt>50<\/strong>\n<\/tt>51\n<\/tt>52\n<\/tt>53\n<\/tt>54\n<\/tt>55<\/strong>\n<\/tt>56\n<\/tt>57\n<\/tt>58\n<\/tt>59\n<\/tt>60<\/strong>\n<\/tt>61\n<\/tt>62\n<\/tt>63\n<\/tt>64\n<\/tt>65<\/strong>\n<\/tt>66\n<\/tt>67\n<\/tt>68\n<\/tt>69\n<\/tt>70<\/strong>\n<\/tt>71\n<\/tt>72\n<\/tt>73\n<\/tt>74\n<\/tt>75<\/strong>\n<\/tt>76\n<\/tt>77\n<\/tt>78\n<\/tt>79\n<\/tt>80<\/strong>\n<\/tt>81\n<\/tt>82\n<\/tt>83\n<\/tt>84\n<\/tt>85<\/strong>\n<\/tt>86\n<\/tt>87\n<\/tt>88\n<\/tt>89\n<\/tt>90<\/strong>\n<\/tt>91\n<\/tt>92\n<\/tt>93\n<\/tt>94\n<\/tt>95<\/strong>\n<\/tt>96\n<\/tt>97\n<\/tt>98\n<\/tt>99\n<\/tt>100<\/strong>\n<\/tt>101\n<\/tt>102\n<\/tt>103\n<\/tt>104\n<\/tt>105<\/strong>\n<\/tt><\/pre>\n<\/td>\n
\n
\n<\/tt>void<\/span> circuit::insert(int<\/span> t, double<\/span> v, int<\/span> n1, int<\/span> n2)\n<\/tt>{\n<\/tt>  node *newNode = getNode(t, v, n1, n2);\n<\/tt>  node *nc = first;\n<\/tt>  node *nc_next = first;\n<\/tt>  if<\/span>(isEmpty())\n<\/tt>  {\n<\/tt>    first = last = newNode;\n<\/tt>    newNode->next = 0<\/span>;\n<\/tt>  }\n<\/tt>  else<\/span> if<\/span>(first == last)\n<\/tt>  {\n<\/tt>    if<\/span>(newNode->node1 < first->node1)\n<\/tt>      insertInFront(newNode);\n<\/tt>    else<\/span> if<\/span>(newNode->node1 > first->node1)\n<\/tt>      insertInBack(newNode, first);\n<\/tt>    else<\/span> \/\/ if newNode->node1 == first->node1<\/span>\n<\/tt>    {\n<\/tt>      if<\/span>(newNode->node2 < first->node2)\n<\/tt>        insertInFront(newNode);\n<\/tt>      else<\/span>\n<\/tt>        insertInBack(newNode, first);\n<\/tt>    }\n<\/tt>  }\n<\/tt>  else<\/span>\n<\/tt>  {\n<\/tt>    while<\/span>(nc->next != 0<\/span>)\n<\/tt>    {\n<\/tt>      if<\/span>(newNode->node1 < nc_next->node1)\n<\/tt>      {\n<\/tt>        if<\/span>(nc_next == first)\n<\/tt>          insertInFront(newNode);\n<\/tt>        else<\/span>\n<\/tt>          insertInMiddle(newNode, nc, nc_next);\n<\/tt>        break<\/span>;\n<\/tt>      }\n<\/tt>      if<\/span>(newNode->node1 == nc_next->node1)\n<\/tt>      {\n<\/tt>        if<\/span>(newNode->node2 <= nc_next->node2)\n<\/tt>        {\n<\/tt>          if<\/span>(nc_next == first)\n<\/tt>            insertInFront(newNode);\n<\/tt>          else<\/span>\n<\/tt>            insertInMiddle(newNode, nc, nc_next);\n<\/tt>          break<\/span>;\n<\/tt>        }\n<\/tt>      }\n<\/tt>      if<\/span>(newNode->node1 >= nc_next->node1 and nc_next == last)\n<\/tt>      {\n<\/tt>        insertInBack(newNode, nc_next);\n<\/tt>        break<\/span>;\n<\/tt>      }\n<\/tt>      nc = nc_next;\n<\/tt>      nc_next = nc->next;\n<\/tt>    }\n<\/tt>  }\n<\/tt>}\n<\/tt>void<\/span> circuit::insertInFront(node *n)\n<\/tt>{\n<\/tt>  n->next = first;\n<\/tt>  first = n;\n<\/tt>}\n<\/tt>void<\/span> circuit::insertInBack(node *n, node *p)\n<\/tt>{\n<\/tt>  p->next = last = n;\n<\/tt>  n->next = 0<\/span>;\n<\/tt>}\n<\/tt>void<\/span> circuit::insertInMiddle(node *cn, node *p , node *n)\n<\/tt>{\n<\/tt>  p->next = cn;\n<\/tt>  cn->next = n;\n<\/tt>}\n<\/tt>bool<\/span> circuit::remove(int<\/span> n1, int<\/span> n2)\n<\/tt>{\n<\/tt>  node *nc = first;\n<\/tt>  node *nc_next = first;\n<\/tt>  node *temp;\n<\/tt>  if<\/span>( isEmpty() )\n<\/tt>    return<\/span> false<\/span>;\n<\/tt>  while<\/span> (nc_next != 0<\/span>)\n<\/tt>  {\n<\/tt>    if<\/span>(nc_next != 0<\/span> and nc_next->node1 == n1 and nc_next->node2 == n2)\n<\/tt>    {\n<\/tt>      temp = nc_next;\n<\/tt>      nc->next = nc_next->next;\n<\/tt>      if<\/span>(first == last)\n<\/tt>        first = last = 0<\/span>;\n<\/tt>      if<\/span>(nc_next == first)\n<\/tt>        first = temp->next;\n<\/tt>      if<\/span> (nc_next == last)\n<\/tt>        last = nc;\n<\/tt>      delete nc_next;\n<\/tt>      return<\/span> true<\/span>;\n<\/tt>    }\n<\/tt>    nc = nc_next;\n<\/tt>    nc_next = nc->next;\n<\/tt>  }\n<\/tt>  return<\/span> false<\/span>;\n<\/tt>}\n<\/tt>bool<\/span> circuit::isEmpty()\n<\/tt>{\n<\/tt>  return<\/span> ( first == 0<\/span> and last == 0<\/span> );\n<\/tt>}\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

Last, we have a friend function<\/b>:<\/p>\n\n\n
\n
1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt>23\n<\/tt><\/pre>\n<\/td>\n
\n
\n<\/tt>ostream & operator << (ostream &os, circuit c)\n<\/tt>{\n<\/tt>  node *nc = c.first; \/\/ node count variable used for looping through list<\/span>\n<\/tt>  int<\/span> lcv = 1<\/span>; \/\/ loop control variable<\/span>\n<\/tt>  cout << "<\/span>First: <\/span>"<\/span><\/span> << c.first << "<\/span>  Last: <\/span>"<\/span><\/span> << c.last << endl;\n<\/tt>  while<\/span> (nc != 0<\/span>)\n<\/tt>  {\n<\/tt>    os << lcv << "<\/span>. <\/span>"<\/span><\/span>\n<\/tt>       << "<\/span>node1: <\/span>"<\/span><\/span>   << nc->getNode1() \n<\/tt>       << "<\/span>  node2: <\/span>"<\/span><\/span> << nc->getNode2()\n<\/tt>       << "<\/span>  type: <\/span>"<\/span><\/span>  << nc->getType() \n<\/tt>       << "<\/span>  value: <\/span>"<\/span><\/span> << nc->getValue() \n<\/tt>       << "<\/span>  next: <\/span>"<\/span><\/span>  << nc->getNext() \n<\/tt>       << endl;\n<\/tt>    nc = nc->getNext();\n<\/tt>    lcv++;\n<\/tt>  }\n<\/tt>  if<\/span>(c.first == 0<\/span>)\n<\/tt>    os << "<\/span>List is empty<\/span>"<\/span><\/span> << endl;\n<\/tt>  return<\/span> os;\n<\/tt>}\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

Testing your program<\/h2>\n

Our teacher gave us a test program, however I expanded it a little bit to test a bit more fully.<\/p>\n

So here is my test program:<\/p>\n\n\n
\n
1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt>23\n<\/tt>24\n<\/tt>25<\/strong>\n<\/tt>26\n<\/tt>27\n<\/tt>28\n<\/tt>29\n<\/tt>30<\/strong>\n<\/tt>31\n<\/tt>32\n<\/tt>33\n<\/tt>34\n<\/tt>35<\/strong>\n<\/tt>36\n<\/tt>37\n<\/tt>38\n<\/tt>39\n<\/tt>40<\/strong>\n<\/tt>41\n<\/tt>42\n<\/tt>43\n<\/tt>44\n<\/tt>45<\/strong>\n<\/tt>46\n<\/tt>47\n<\/tt>48\n<\/tt>49\n<\/tt>50<\/strong>\n<\/tt>51\n<\/tt>52\n<\/tt>53\n<\/tt>54\n<\/tt>55<\/strong>\n<\/tt>56\n<\/tt>57\n<\/tt>58\n<\/tt>59\n<\/tt>60<\/strong>\n<\/tt>61\n<\/tt>62\n<\/tt>63\n<\/tt>64\n<\/tt>65<\/strong>\n<\/tt>66\n<\/tt>67\n<\/tt>68\n<\/tt>69\n<\/tt>70<\/strong>\n<\/tt>71\n<\/tt>72\n<\/tt>73\n<\/tt>74\n<\/tt>75<\/strong>\n<\/tt>76\n<\/tt><\/pre>\n<\/td>\n
\n
\n<\/tt>#include<\/span> <iostream><\/span>\n<\/tt>#include<\/span> "yourprogramname.h"<\/span>\n<\/tt>using namespace std;\n<\/tt>\n<\/tt>const<\/span> int<\/span> M=7<\/span>;\n<\/tt>const<\/span> int<\/span> R=2<\/span>;\n<\/tt>\n<\/tt>int<\/span> main()\n<\/tt>{\n<\/tt>  circuit c, c2, c3;\n<\/tt>  int<\/span> d[M*3<\/span>] = {1<\/span>,1<\/span>,4<\/span>, 1<\/span>,1<\/span>,3<\/span>, 2<\/span>,2<\/span>,3<\/span>, 1<\/span>,1<\/span>,2<\/span>, 1<\/span>,5<\/span>,6<\/span>, 1<\/span>,2<\/span>,5<\/span>, 3<\/span>,1<\/span>,3<\/span>};\n<\/tt>  double<\/span> v[M] = {1<\/span>0<\/span>.5<\/span>, 3<\/span>0<\/span>.7<\/span>, 10<\/span>0<\/span>.4<\/span>, 2<\/span>0<\/span>.6<\/span>, 3<\/span>5<\/span>.5<\/span>, 4<\/span>5<\/span>.9<\/span>, 6<\/span>0<\/span>.8<\/span>};\n<\/tt>  int<\/span> d1[R*8<\/span>] = {1<\/span>,2<\/span>, 5<\/span>,6<\/span>, 3<\/span>,6<\/span>, 1<\/span>,4<\/span>, 1<\/span>,3<\/span>, 2<\/span>,5<\/span>, 2<\/span>,3<\/span>, 1<\/span>,3<\/span>};\n<\/tt>  int<\/span> i, j;\n<\/tt>\n<\/tt>  for<\/span>( i=0<\/span>,j=0<\/span>; i<M; i++,j=j+3<\/span> )\n<\/tt>  {\n<\/tt>    cout << i+1<\/span> << endl;\n<\/tt>    cout << "<\/span>Inserting new node into list with:<\/span>"<\/span><\/span> << endl;\n<\/tt>    cout << "<\/span>node1: <\/span>"<\/span><\/span>   << d[j+1<\/span>]\n<\/tt>         << "<\/span>  node2: <\/span>"<\/span><\/span> << d[j+2<\/span>]\n<\/tt>         << "<\/span>  type: <\/span>"<\/span><\/span>  << d[j]\n<\/tt>         << "<\/span>  value: <\/span>"<\/span><\/span> << v[i]\n<\/tt>         << endl;\n<\/tt>    c.insert( d[j], v[i], d[j+1<\/span>], d[j+2<\/span>] );\n<\/tt>    cout << "<\/span>List: <\/span>"<\/span><\/span> << endl;\n<\/tt>    cout << c << endl << endl;\n<\/tt>  }\n<\/tt>  for<\/span>( i=0<\/span>; i<R*8<\/span>; i=i+2<\/span> )\n<\/tt>  {\n<\/tt>    cout << "<\/span>Removing node with:<\/span>"<\/span><\/span> << endl;\n<\/tt>    cout << "<\/span>node1: <\/span>"<\/span><\/span>   << d1[i]\n<\/tt>         << "<\/span>  node2: <\/span>"<\/span><\/span> << d1[i+1<\/span>]\n<\/tt>         << endl;\n<\/tt>    if<\/span>( c.remove( d1[i], d1[i+1<\/span>] ) == false<\/span> )\n<\/tt>      cout << "<\/span>Node not found<\/span>"<\/span><\/span> << endl;\n<\/tt>    cout << "<\/span>List: <\/span>"<\/span><\/span> << endl;\n<\/tt>    cout << c << endl << endl;\n<\/tt>  }\n<\/tt>\n<\/tt>  cout << "<\/span>n<\/span>n<\/span>Making List #2:<\/span>"<\/span><\/span> << endl;\n<\/tt>  int<\/span> d2[M*3<\/span>] = {2<\/span>,2<\/span>,4<\/span>, 1<\/span>,1<\/span>,3<\/span>, 2<\/span>,2<\/span>,3<\/span>, 1<\/span>,1<\/span>,2<\/span>, 1<\/span>,5<\/span>,6<\/span>, 1<\/span>,2<\/span>,5<\/span>, 3<\/span>,1<\/span>,3<\/span>};\n<\/tt>  for<\/span>( i=0<\/span>,j=0<\/span>; i<M; i++,j=j+3<\/span> )\n<\/tt>  {\n<\/tt>    cout << i+1<\/span> << endl;\n<\/tt>    cout << "<\/span>Inserting new node into list with:<\/span>"<\/span><\/span> << endl;\n<\/tt>    cout << "<\/span>node1: <\/span>"<\/span><\/span>   << d2[j+1<\/span>]\n<\/tt>         << "<\/span>  node2: <\/span>"<\/span><\/span> << d2[j+2<\/span>]\n<\/tt>         << "<\/span>  type: <\/span>"<\/span><\/span>  << d2[j]\n<\/tt>         << "<\/span>  value: <\/span>"<\/span><\/span> << v[i]\n<\/tt>         << endl;\n<\/tt>    c2.insert( d2[j], v[i], d2[j+1<\/span>], d2[j+2<\/span>] );\n<\/tt>    cout << "<\/span>List: <\/span>"<\/span><\/span> << endl;\n<\/tt>    cout << c2 << endl << endl;\n<\/tt>  }\n<\/tt>\n<\/tt>  cout << "<\/span>n<\/span>n<\/span>Making List #3:<\/span>"<\/span><\/span> << endl;\n<\/tt>  int<\/span> d3[M*3<\/span>] = {2<\/span>,2<\/span>,4<\/span>, 3<\/span>,3<\/span>,3<\/span>, 2<\/span>,2<\/span>,3<\/span>, 1<\/span>,1<\/span>,2<\/span>, 1<\/span>,5<\/span>,6<\/span>, 1<\/span>,2<\/span>,5<\/span>, 3<\/span>,1<\/span>,3<\/span>};\n<\/tt>  for<\/span>( i=0<\/span>,j=0<\/span>; i<M; i++,j=j+3<\/span> )\n<\/tt>  {\n<\/tt>    cout << i+1<\/span> << endl;\n<\/tt>    cout << "<\/span>Inserting new node into list with:<\/span>"<\/span><\/span> << endl;\n<\/tt>    cout << "<\/span>node1: <\/span>"<\/span><\/span>   << d3[j+1<\/span>]\n<\/tt>         << "<\/span>  node2: <\/span>"<\/span><\/span> << d3[j+2<\/span>]\n<\/tt>         << "<\/span>  type: <\/span>"<\/span><\/span>  << d3[j]\n<\/tt>         << "<\/span>  value: <\/span>"<\/span><\/span> << v[i]\n<\/tt>         << endl;\n<\/tt>    c3.insert( d3[j], v[i], d3[j+1<\/span>], d3[j+2<\/span>] );\n<\/tt>    cout << "<\/span>List: <\/span>"<\/span><\/span> << endl;\n<\/tt>    cout << c3 << endl << endl;\n<\/tt>  }\n<\/tt>\n<\/tt>  return<\/span> 0<\/span>;\n<\/tt>}\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"

This is a step-by-step tutorial for this assignment and an explanation of the basics of how it works for those that are having a difficult time understanding or just are stuck somewhere. To view the assignment click here. So for this assignment we are only going to be doing input and output. So the only […]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[32,6,3,14,30],"tags":[33,34,35],"_links":{"self":[{"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/posts\/52831"}],"collection":[{"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/comments?post=52831"}],"version-history":[{"count":2,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/posts\/52831\/revisions"}],"predecessor-version":[{"id":57504,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/posts\/52831\/revisions\/57504"}],"wp:attachment":[{"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/media?parent=52831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/categories?post=52831"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/tags?post=52831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}