Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Cell
- {
- public:
- double val;
- Cell* next;
- Cell* prev;
- Cell(double v)
- {
- val = v;
- next = NULL;
- prev = NULL;
- }
- };
- class List
- {
- private:
- Cell* head = NULL;
- Cell* tail = NULL;
- public:
- Cell* begin(){
- return head;
- }
- Cell* end(){
- return tail;
- }
- void push_front(double v)
- {
- if (head == NULL)
- {
- head = new Cell(v);
- tail = head;
- }
- else
- {
- Cell* n = new Cell(v);
- n->next = head;
- head->prev = n;
- head = n;
- }
- }
- void push_back( double v )
- {
- if( head == NULL ){
- head = new Cell(v);
- tail = head;
- }
- else
- {
- Cell* n = new Cell(v);
- n->prev = tail;
- tail->next = n;
- tail = n;
- }
- }
- void remove( int index ){
- Cell* elem = head;
- for( int i = 0; i < index; i++ ){
- elem = elem->next;
- }
- elem->prev->next = elem->next;
- elem->next->prev = elem->prev;
- }
- int find( double elem ){
- Cell* curr = head;
- int i = 0;
- while (curr != NULL)
- {
- if( curr->val == elem ){
- return i;
- }
- curr = curr->next;
- i++;
- }
- return -1;
- }
- void print()
- {
- Cell* curr = head;
- while (curr != NULL)
- {
- cout << curr->val << " ";
- curr = curr->next;
- }
- cout << endl;
- }
- };
- int main()
- {
- int n;
- cout << "Enert n: ";
- cin >> n;
- if( n >= 2 ){
- List data;
- for( int i = 0; i < n; i++ ){
- double elem;
- cout << "Enter " << i + 1 << " element: ";
- cin >> elem;
- data.push_back(elem);
- }
- double ans = 1;
- Cell* start = data.begin();
- Cell* end = data.end();
- for( int i = 0; i < n; i++ ){
- double elem;
- elem = start->val * end->val;
- start = start->next;
- end = end->prev;
- ans = ans * elem;
- }
- cout << "Answer is " << ans << endl;
- }else{
- cout << "ERROR: n is too small" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement