void test_copy_assignment_empty_non_empty() { #ifndef TEST_HAS_NO_EXCEPTIONS using MET = MakeEmptyT; { using V = std::variant<int, MET>; V v1(std::in_place_index<0>); makeEmpty(v1); V v2(std::in_place_index<0>, 42); V &vref = (v1 = v2); assert(&vref == &v1); assert(v1.index() == 0); assert(std::get<0>(v1) == 42); } { using V = std::variant<int, MET, std::string>; V v1(std::in_place_index<0>); makeEmpty(v1); V v2(std::in_place_type<std::string>, "hello"); V &vref = (v1 = v2); assert(&vref == &v1); assert(v1.index() == 2); assert(std::get<2>(v1) == "hello"); } #endif }
void makeEmpty(TreeNode T) { if (T != NULL) { makeEmpty(T->Left); makeEmpty(T->Right); free(T); } }
void makeEmpty(SkewHeap H) { if (H != NULL) { makeEmpty(H->Left); makeEmpty(H->Right); free(H); } }
int main(){ /*make list and output file*/ ListHndl TheList = newList(); FILE *out = fopen("out.out", "w"); /*test empty in empty case*/ if(isEmpty(TheList)) printf("Empty\n"); else printf("not Empty\n"); printf("testing insert one number\n"); insertAtFront(TheList,(unsigned long*)25728); printf("%lu\n",(unsigned long)getFirst(TheList)); printf("%lu\n",(unsigned long)getLast(TheList)); /*should have same value*/ printf("testing list with three numbers\n"); insertAtFront(TheList,(unsigned long*)1589458); insertAtBack(TheList,(unsigned long*)35762111234); printf("%lu\n",(unsigned long)getFirst(TheList)); /*test empty in full case*/ if(isEmpty(TheList)) printf("Empty\n"); else printf("not Empty\n"); /*test moving the current pointer around*/ moveFirst(TheList); moveNext(TheList); printf("%lu\n",(unsigned long)getCurrent(TheList)); moveLast(TheList); movePrev(TheList); printf("%lu\n",(unsigned long)getCurrent(TheList)); /*test printList*/ printList(out, TheList); /*test makeEmpty*/ makeEmpty(TheList); if(isEmpty(TheList)) printf("Empty\n"); else printf("not Empty\n"); /*test inserting functions*/ insertAtFront(TheList,(unsigned long*)2); insertAtFront(TheList,(unsigned long*)1); insertAtFront(TheList,(unsigned long*)4); insertAtBack(TheList,(unsigned long*)4); moveLast(TheList); insertBeforeCurrent(TheList,(unsigned long*)3); printList(out,TheList); deleteFirst(TheList); deleteCurrent(TheList); deleteLast(TheList); printList(out,TheList); makeEmpty(TheList); printList(out,TheList); /*free list and close output file*/ freeList(&TheList); fclose(out); return 0; }
void test_copy_assignment_non_empty_empty() { #ifndef TEST_HAS_NO_EXCEPTIONS using MET = MakeEmptyT; { using V = std::variant<int, MET>; V v1(std::in_place_index<0>, 42); V v2(std::in_place_index<0>); makeEmpty(v2); V &vref = (v1 = v2); assert(&vref == &v1); assert(v1.valueless_by_exception()); assert(v1.index() == std::variant_npos); } { using V = std::variant<int, MET, std::string>; V v1(std::in_place_index<2>, "hello"); V v2(std::in_place_index<0>); makeEmpty(v2); V &vref = (v1 = v2); assert(&vref == &v1); assert(v1.valueless_by_exception()); assert(v1.index() == std::variant_npos); } #endif }
/** * Internal method to make subtree empty. */ void AvlTree::makeEmpty( AvlNode * & t ) const { if ( t != NULL ) { makeEmpty( t->left ); makeEmpty( t->right ); delete t; } t = NULL; }
void BinarySearchTree::makeEmpty( BinaryNode * & t ) const { if ( t != NULL ) { makeEmpty( t->left ); makeEmpty( t->right ); delete t; } t = NULL; }
BST *makeEmpty(BST *root){ if(root != NULL){ makeEmpty(root->left); makeEmpty(root->right); free(root); } return(NULL); }
avlTree makeEmpty(avlTree T){ if(T != NULL){ makeEmpty(T->left); makeEmpty(T->right); free(T); } return NULL; }
/** * Internal method to make subtree empty. */ void makeEmpty(BinaryNode * &t){ if (t != NULL){ makeEmpty(t->left); makeEmpty(t->right); delete t; } t = NULL; }
/** A helper method to destruct the tree and kill every node */ void HCTree::makeEmpty(HCNode *&h) { if(h != 0) { makeEmpty(h->c0); makeEmpty(h->c1); delete h; } h = 0; }
// make the BinarySearchTree empty BinarySearchTree makeEmpty(BinarySearchTree t) { if(t){ makeEmpty(t->left); makeEmpty(t->right); free(t); } return NULL; }
// makeEmpty helper // Removes and deletes all nodes from the tree, and sets m_root equal to // nullptr. // preconditions: this not equal to nullptr // postconditions: All nodes removed and deleted, m_root set to nullptr // void BSTree::makeEmpty(Node *node) { if(node != nullptr) { makeEmpty(node->m_left); makeEmpty(node->m_right); delete node->m_item; node->m_item = nullptr; delete node; node = nullptr; } }
// ------------------------------------MakeEmpty----------------------------------------------- // Description: recursively works through tree deleting nodes // resets root to NULL to make old tree recycleable // ------------------------------------------------------------------------------------------------------------- void BinTree::makeEmpty(Node* sub) { if(sub != NULL) { makeEmpty(sub->left); makeEmpty(sub->right); delete sub; } root = NULL; }
void AATree<Comparable>::makeEmpty( AANode<Comparable> * & t ) { if( t != nullNode ) { makeEmpty( t->left ); makeEmpty( t->right ); delete t; } t = nullNode; }
void BST<T>::makeEmpty(BSTNode* &t) { if (t != nullptr) { makeEmpty(t->left); makeEmpty(t->right); delete t; t = nullptr; } }
static void makeEmpty(Node* &t) { if (t == nullptr) { return; } makeEmpty(t->left); makeEmpty(t->right); delete t; t = nullptr; }
// assignment // Sets this equal to tree. Performs a deep copy. // preconditions: tree must be a valid BSTree object (must not reference // a dereferenced nullptr); this not equal to nullptr. // postconditions: this becomes an identical node-by-node copy of tree, // creating new Nodes and new TreeDatas. // const BSTree& BSTree::operator=(const BSTree &tree) { if(this != &tree) { makeEmpty(); copyNode(m_root, tree.m_root); } return(*this); }
/* DFS */ void DFS(GraphRef G, ListRef S){ int i, s, top, low; moveTo(S, 0); s = getCurrent(S); G->parent[s] = 0; for(i=0;i<=getLength(S);i++){ if(G->color[s] == 1){ G->parent[s] = 0; visit(G, s); } if(i<getLength(S)-1){ moveNext(S); s = getCurrent(S); } } makeEmpty(S); top = getTime(G); while(getLength(S) < getOrder(G)){ low = 0; for(i=1;i<=getOrder(G);i++){ if(top > G->finish[i] && low < G->finish[i]){ low = G->finish[i]; s = i; } } insertBack(S, s); top = low; } }
//<<<<<<<<<<<<<<<<<<<<<<<<<<<< readMesh >>>>>>>>>>>>>>>>>>>>>>>> void Mesh:: readMesh(string fname) { fstream inStream; inStream.open(fname.c_str(), ios ::in); //open needs a c-like string if(inStream.fail() || inStream.eof()) { cout << "can't open file or eof: " << fname << endl; makeEmpty();return; } inStream >> numVerts >> numNorms >> numFaces; // make arrays for vertices, normals, and faces pt = new Point3[numVerts]; assert(pt != NULL); norm = new Vector3[numNorms]; assert(norm != NULL); face = new Face[numFaces]; assert(face != NULL); for(int i = 0; i < numVerts; i++) // read in the vertices inStream >> pt[i].x >> pt[i].y >> pt[i].z; for(int ii = 0; ii < numNorms; ii++) // read in the normals inStream >> norm[ii].x >> norm[ii].y >> norm[ii].z; for(int f = 0; f < numFaces; f++) // read in face data { inStream >> face[f].nVerts; int n = face[f].nVerts; face[f].vert = new VertexID[n]; assert(face[f].vert != NULL); for(int k = 0; k < n; k++) // read vertex indices for this face inStream >> face[f].vert[k].vertIndex; for(int kk = 0; kk < n; kk++) // read normal indices for this face inStream >> face[f].vert[kk].normIndex; } inStream.close(); } // end of readMesh
void doBFS(GraphRef g, int source){ ListRef list = newList(); initGraph(g); insertAfterLast(list, source); g->color[source]= 1; g->distance[source]=0; while(!isEmpty(list)){ int current = getFirst(list); if(current > g->numVertices){ deleteFirst(list); break; } ListRef edgeList = g->vertices[current]; moveFirst(edgeList); while(!offEnd(edgeList)){ int edge = getCurrent(edgeList); if(g->color[edge]==0){ g->distance[edge] = g->distance[current]+1; g->color[edge] = 1; g->parent[edge] = current; insertAfterLast(list, edge); } moveNext(edgeList); } deleteFirst(list); g->color[current] = 2; } makeEmpty(list); freeList(list); }
/*Main function that reads in every transaction*/ void readTransactions(FILE* f, int numCustomers, int numTransactions){ HashRef h = createHashSet(); int custNum, wantPrint; int count =0; long bookId; ListRef customers[numCustomers]; for(int i=0; i<numCustomers+1; i++) customers[i] = newList(); while(count < numTransactions){ ++count; fscanf(f, "%d", &custNum); fscanf(f, "%lu", &bookId); fscanf(f, "%d", &wantPrint); if(hasBook(customers[custNum],bookId)){ //customer already bought book // checkPurchased(customers, custNum, bookId); insertionSort(customers[custNum], bookId); } else{ addCopurchase(h, bookId, customers, custNum); insertionSort(customers[custNum], bookId); } if(wantPrint){ printRecommendation(h, bookId, customers, custNum); } } //debugHash(h);//uncomment me to see the hash status destroy(h); for(int i=0; i<numCustomers+1; i++){ makeEmpty(customers[i]); freeList(customers[i]); } }
void BinarySearchTree<T>::makeEmpty(BinarySearchTreeNode<T>* node) { if (node != NULL) { if (node->left != NULL) makeEmpty(node->left); if (node->right != NULL) makeEmpty(node->right); delete node; node = NULL; size--; } }
int main() { { using V = std::variant<int, ConstexprTestTypes::NoCtors>; constexpr V v; static_assert(v.index() == 0, ""); } { using V = std::variant<int, long>; constexpr V v(std::in_place_index<1>); static_assert(v.index() == 1, ""); } { using V = std::variant<int, std::string>; V v("abc"); assert(v.index() == 1); v = 42; assert(v.index() == 0); } #ifndef TEST_HAS_NO_EXCEPTIONS { using V = std::variant<int, MakeEmptyT>; V v; assert(v.index() == 0); makeEmpty(v); assert(v.index() == std::variant_npos); } #endif }
void GraphL::buildGraph(istream& infile) { int fromNode, toNode; // from and to node ends of edge makeEmpty(); // clear the graph of memory infile >> size; // read the number of nodes if (infile.eof()) return; // stop if no more data string s; // used to read through to end of line getline(infile, s); // read graph node information for (int i = 1; i <= size; i++) { // read using setData of the NodeData class, // something like: // adjList[i].data.setData(infile); // where adjList is the array of GraphNodes and // data is the NodeData object inside of GraphNode } // read the edge data and add to the adjacency list for (;;) { infile >> fromNode >> toNode; if (fromNode == 0 && toNode == 0) return; // end of edge data // insert the edge into the adjacency list for fromNode } }
int main(int argc, char const *argv[]) { BOX *prvni = makeEmpty( 10); return 0; }
/** * Deep copy */ const BinarySearchTree& operator =(const BinarySearchTree& rhs){ if (*this != rhs){ makeEmpty(); root = clone(rhs.root); } return *this; }
/* Free the list and release the resources */ void freeList(ListRef* pL) { if (pL != NULL && *pL != NULL) { makeEmpty(*pL); free(*pL); *pL = NULL; } }
Dlist<T>::Dlist() { //std::cout << "Constructor Called\n\n"; this->first = new node; this->last = new node; makeEmpty(); //std::cout << "Constructor completed\n\n"; }
const BST<T>& BST<T>::operator= (BST&& tree) { makeEmpty(); root = move(tree.root); tree.root = nullptr; rotate_threshold_value = tree.rotate_threshold_value; return *this; }