Write the isAltSequence method using C++ program.
//
*********************************************************
// Node constructors: do not change
Node::Node(int item) {
data = item;
next = NULL;
}
Node::Node(int item, Node *n) {
data = item;
next = n;
}
//*************************************************************************
// Node type used for lists
struct Node {
int data;
Node *next;
Node(int item);
Node(int item, Node *n);
};
typedef Node * ListType;
//*************************************************************************
// Functions you need to write for this assignment:
// (implementations go in ecListFuncs.cpp)
/*
* Note: examples of linked lists here are shown as a space
separated list of numbers
* surrounded by parentheses. This is also the format of
the string produced by
* listToString, below.
*/
/**
isAltSequence
PRE: list is a well-formed list
Returns true iff the list is an alternating
sequence, where an alternating sequence is defined
as one where the first two values are increasing (or
decreasing), the second and third value
go in the opposite direction (e.g., decreasing if the
first two were increasing), continuing
on with these alternating directions until the end of
the list. Such a list will have no
areas where two ajacent values are the same. The
examples below also show how the function
should behave for short lists.
Examples:
list
isAltSequence(list)
(7 4 5 2 12 -10) true
(7 4 3 5 2 12 -10) false
(7 4 5 12 15) false
(7 4 4 8 2 12 -10) false
(4 7 4 5 2)
true
(1 3 2)
true
(3 3 3)
false
(1 2)
true
(2 1)
true
(2 2)
false
(32)
true
()
true
*/
bool isAltSequence(ListType list);
Write the isAltSequence method using C++ program. // ********************************************************* // Node c
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Write the isAltSequence method using C++ program. // ********************************************************* // Node c
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!