MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_LinkedList.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include <stddef.h> // for NULL
11 #include "MueLu_LinkedList.hpp"
12 
13 namespace MueLu {
14 
16  : nodeHead(NULL)
17  , nodeTail(NULL) {}
18 
20  while (nodeHead != NULL)
21  DeleteHead();
22 }
23 
25  return nodeHead == NULL;
26 }
27 
28 void LinkedList::Add(int iNode) {
29  MueLu_Node *newNode = new MueLu_Node;
30  newNode->nodeId = iNode;
31  newNode->next = NULL;
32  if (nodeHead == NULL) {
33  nodeHead = newNode;
34  nodeTail = newNode;
35  } else {
36  nodeTail->next = newNode;
37  nodeTail = newNode;
38  }
39 }
40 
41 int LinkedList::Pop() { // get head and remove first node
42  if (IsEmpty()) return -1;
43 
44  int iNode = nodeHead->nodeId;
45  DeleteHead();
46  return iNode;
47 }
48 
50  if (IsEmpty()) return;
51 
52  MueLu_Node *newNode = nodeHead;
53  nodeHead = newNode->next;
54  delete newNode;
55 }
56 
57 } // namespace MueLu
58 
59 // TODO: nodeTail unused -> remove?
struct MueLu::MueLu_Node_Struct MueLu_Node
struct MueLu_Node_Struct * next
void Add(int iNode)