/* * Read the lines from the configuration file and * add them to the list of paths. */ static void readfp(qelem *q0, FILE *fp) { char cline[LINE_MAX]; int nread = 0; qelem q; /* * Make a new empty list. */ q.q_forw = q.q_back = &q; /* * Read the lines from the configuration file. */ while (fgets(cline, sizeof(cline), fp)) { path *p = palloc(cline, nread+1); if (p && !pinsert(p, &q)) pfree(p); nread++; } /* * If some records were read, then throw * away the old list and replace with the * new one. */ if (nread) preplace(q0, &q); }
bool pinsert(const Z& key, Node * & t, Node * p){ if(t == nullptr){ t = new Node; t->data = key; nums++; t->left = nullptr; t->right = nullptr; t->parent = p; return true; } else if(key < t->data) pinsert(key, t->left, t); else if(key > t->data) pinsert(key, t->right, t); return false; }
bool insert (const Z& key) { return pinsert(key, rootPtr, nullptr); }