chooser::pitem chooser::delete_element(pitem p) { pitem res = nullptr; if (!p->L && !p->R) { if (p->parent) { res = p->parent; if (is_left_child(p)) { res->L = nullptr; } else { res->R = nullptr; } } delete p; } else if (!p->L || !p->R) { if (p->parent) { res = p->parent; if (is_left_child(p)) { res->L = p->L ? p->L : p->R; } else { res->R = p->L ? p->L : p->R; } p->L = p->R = nullptr; delete p; } else { if (p->L) { right_rotale(p); } else { left_rotale(p); } return delete_element(p); } } else { pitem q = leftmost_child(p->R); if (q != p->R) { std::swap(p->L, q->L); std::swap(p->R, q->R); recalc(p); recalc(q); const pitem p_par = p->parent; make_parent(q->parent, p); make_parent(p_par, q); } else { left_rotale(p); } assert(!p->L || !p->R); delete_element(p); res = q->parent ? q->parent : q; } recalc(res); return splay(res); }
/* * Ensure that all directories leading up to (but not including) the * specified path exist. * * XXX inefficient + modifies the file in-place */ static void make_parent(char *path) { struct stat sb; char *sep; sep = strrchr(path, '/'); if (sep == NULL || sep == path) return; *sep = '\0'; if (lstat(path, &sb) == 0) { if (S_ISDIR(sb.st_mode)) { *sep = '/'; return; } unlink(path); } make_parent(path); mkdir(path, 0755); *sep = '/'; #if 0 for (sep = path; (sep = strchr(sep, '/')) != NULL; sep++) { /* root in case of absolute d_arg */ if (sep == path) continue; *sep = '\0'; make_dir(path, 0755); *sep = '/'; } #endif }
inline void chooser::right_rotale(pitem p) { assert(p->L); pitem q = p->L; if (p->parent) { if (is_left_child(p)) { p->parent->L = q; } else { p->parent->R = q; } } p->L = q->R; q->R = p; recalc(p->L); recalc(p); make_parent(p->parent, q); make_parent(q, p); recalc(q); recalc(q->parent); }
void check(int x,int y) { int p=Find(x); int q=Find(y); if(p!=q) { make_parent(p,q); printf("Make friend\n"); return; } printf("they allready friend\n"); return; }
/* * Extract a zipfile entry: first perform some sanity checks to ensure * that it is either a directory or a regular file and that the path is * not absolute and does not try to break out of the current directory; * then call either extract_dir() or extract_file() as appropriate. * * This is complicated a bit by the various ways in which we need to * manipulate the path name. Case conversion (if requested by the -L * option) happens first, but the include / exclude patterns are applied * to the full converted path name, before the directory part of the path * is removed in accordance with the -j option. Sanity checks are * intentionally done earlier than they need to be, so the user will get a * warning about insecure paths even for files or directories which * wouldn't be extracted anyway. */ static void extract(struct archive *a, struct archive_entry *e) { char *pathname, *realpathname; mode_t filetype; char *p, *q; pathname = pathdup(archive_entry_pathname(e)); filetype = archive_entry_filetype(e); /* sanity checks */ if (pathname[0] == '/' || strncmp(pathname, "../", 3) == 0 || strstr(pathname, "/../") != NULL) { warningx("skipping insecure entry '%s'", pathname); ac(archive_read_data_skip(a)); free(pathname); return; } /* I don't think this can happen in a zipfile.. */ if (!S_ISDIR(filetype) && !S_ISREG(filetype)) { warningx("skipping non-regular entry '%s'", pathname); ac(archive_read_data_skip(a)); free(pathname); return; } /* skip directories in -j case */ if (S_ISDIR(filetype) && j_opt) { ac(archive_read_data_skip(a)); free(pathname); return; } /* apply include / exclude patterns */ if (!accept_pathname(pathname)) { ac(archive_read_data_skip(a)); free(pathname); return; } /* apply -j and -d */ if (j_opt) { for (p = q = pathname; *p; ++p) if (*p == '/') q = p + 1; realpathname = pathcat(d_arg, q); } else { realpathname = pathcat(d_arg, pathname); } /* ensure that parent directory exists */ make_parent(realpathname); if (S_ISDIR(filetype)) extract_dir(a, e, realpathname); else extract_file(a, e, &realpathname); free(realpathname); free(pathname); }