Use C++ to write this method Node::Node(int item) { data = item; next = NULL; } Node::Node(int item, Node *n) { data = i
Posted: Mon May 09, 2022 6:10 am
Use C++ to write this method
Node::Node(int item) {
data = item;
next = NULL;
}
Node::Node(int item, Node *n) {
data = item;
next = n;
}
struct Node {
int data;
Node *next;
Node(int item);
Node(int item, Node *n);
};
typedef Node * ListType;
/** collapseRepeats PRE: list is a well-formed list Removes any
repeating adjacent values in the list, keeping the first copy of
the value. E
xamples (list' indicates the value of list after the call):
list list'
(1 1 3 3 3 1 1 1 1 5 2 7 7) (1 3 1 5 2 7)
(1 3 1 5 2 7) (1 3 1 5 2 7)
() ()
(12) (12) */
void collapseRepeats(ListType & list);
Node::Node(int item) {
data = item;
next = NULL;
}
Node::Node(int item, Node *n) {
data = item;
next = n;
}
struct Node {
int data;
Node *next;
Node(int item);
Node(int item, Node *n);
};
typedef Node * ListType;
/** collapseRepeats PRE: list is a well-formed list Removes any
repeating adjacent values in the list, keeping the first copy of
the value. E
xamples (list' indicates the value of list after the call):
list list'
(1 1 3 3 3 1 1 1 1 5 2 7 7) (1 3 1 5 2 7)
(1 3 1 5 2 7) (1 3 1 5 2 7)
() ()
(12) (12) */
void collapseRepeats(ListType & list);