public bool delete(string login)//*, spisok_tariph.nest tariph*//*) { nest curr = find(login); if (curr != null) { if (curr != curr.prev && curr != curr.next) { if (curr == table[get_hash(login)]) { table[get_hash(login)] = curr.next; } curr.prev.next = curr.next; curr.next.prev = curr.prev; curr.next = null; curr.prev = null; } else { curr.next = null; curr.prev = null; curr = null; } return(true); } else { return(false); } }
/* public bool add(string login, string date, spisok_tariph.nest tariph) * { * int curr_hash = get_hash(login); * nest curr = first; * * * if (curr == null) * { * first = new nest(); * first.hash = curr_hash; * first.login = login; * first.date = date; * * first.tariph = tariph; * first.next = first; * first.prev = first; * first.chain_next = null; * * return true; * } * else * { * while (true) * { * while ((curr.hash != curr_hash) && (curr.next != first) && (curr_hash > curr.hash)) * { * curr = curr.next; * } * * if ((curr.hash > curr_hash)&&(curr == first)) * { * nest temp = new nest(); * temp.login = login; * temp.date = date; * temp.tariph = tariph; * temp.hash = curr_hash; * first.prev.next = temp; * temp.prev = first.prev; * first.prev = temp; * temp.next = first; * first = temp; * temp.chain_next = null; * return true; * } * if ((curr.next == first)&&(curr_hash>curr.hash)) * { * nest temp = new nest(); * temp.login = login; * temp.date = date; * temp.tariph = tariph; * temp.hash = curr_hash; * * curr.next = temp; * temp.prev = curr; * temp.next = first; * first.prev = temp; * * temp.chain_next = null; * return true; * } * else if(curr_hash<curr.hash) * { * nest temp = new nest(); * temp.login = login; * temp.date = date; * temp.hash = curr_hash; * temp.tariph = tariph; * * curr.prev.next = temp; * temp.prev = curr.prev; * curr.prev = temp; * temp.next = curr; * temp.chain_next = null; * return true; * } * else * { * while (curr.chain_next != null) * curr = curr.chain_next; * nest temp = new nest(); * temp.login = login; * temp.date = date; * temp.hash = curr_hash; * temp.tariph = tariph; * * temp.chain_next = null; * temp.chain_prev = curr; * curr.chain_next = temp; * return true; * } * * } * } * * * }*/ public bool add(string login, string date, spisok_tariph.nest tariph) { nest temp = new nest(login, date, tariph); int hash = get_hash(login); if (table[hash] == null) { table[hash] = temp; table[hash].next = table[hash]; table[hash].prev = table[hash]; return(true); } else { temp.next = table[hash].next; table[hash].next.prev = temp; table[hash].next = temp; temp.prev = table[hash]; /*nest newtemp = table[hash].next; * table[hash].next = newtemp; * newtemp.prev = table[hash]; * newtemp.next = table[hash].next.next; * table[hash].next.next.prev = newtemp*/ return(true); } }
public bool free(nest temp)//проверка на пустую ячейку { if (((temp.name == "") && (temp.provider == null)) || (temp.deleted)) { return(true); } else { return(false); } }
public void Main(string[] args) { diff sam = new diff(); nest n = new nest(); nest.inner ni = new nest.inner(); ni.innermethod(); Console.WriteLine(nest.inner.x); sam.sample(); }
/* public class nest * { * public int hash; * public string login; * public string date; * public spisok_tariph.nest tariph; * public spisok_users.nest chain;//для метода цепочек * * public nest next, prev, chain_next, chain_prev; *//*public nest(int i) * { * hash = i; * login = ""; * date = ""; * * }*//* * }*/ //public nest first; /* public spisok_users() * { * first = null; * max_elements = 100;*/ //num_of_elements = 0; /*first = new nest(0); * nest curr = first; * for (int i = 1; i < max_elements; i++) * { * curr.next = new nest(i); * curr.next.prev = curr; * curr = curr.next; * } * curr.next = first; * first.prev = curr; * curr.chain_next = null; * curr.chain_prev = curr; * * }*/ public bool free(nest temp)//проверка на пустую ячейку { //return ((temp.login == "") && (temp.tariph == null)); if (((temp.login == "") && (temp.tariph == null)) || (temp == null)) { return(false); } else { return(true); } //return ((temp.login == "") && (temp.tariph == null)) || (temp == null); }
public void delete(string name, tree_providers.root provider) { nest curr = find(name, provider); if (curr != null) { //num_of_elements; curr.deleted = true; } else { //error } }
public void resize(bool hash)//увеличиваем размер таблицы { max_elements *= 2; nest[] temp = mas; mas = new nest[max_elements]; for (int i = 0; i < max_elements; i++) { mas[i] = new nest(); } for (int i = 0; i < max_elements / 2; i++) { if (!free(temp[i])) { if (hash) { add(getkey(temp[i].name, ""), temp[i].name, temp[i].type, temp[i].speed, temp[i].provider); } else { add(temp[i].name, temp[i].type, temp[i].speed, temp[i].provider); } num_of_elements--; } } //nest temp_first = first; //first = new nest(0); //nest curr = first; /*for (int i = 1; i < max_elements; i++)//создание новой таблицы * { * curr.next = new nest(i); * curr.next.prev = curr; * curr = curr.next; * } * curr.next = first; * first.prev = curr; * for (int i = 0; i < num_of_elements; i++)//перезаписывание в новую таблицу * { * add(getkey(temp_first.name, temp_first.provider.title), temp_first.name, temp_first.type, temp_first.speed, temp_first.provider); * num_of_elements--; * temp_first = temp_first.next; * * }*/ }
public spisok_tariph() { num_of_elements = 0; max_elements = 8; mas = new nest[max_elements]; for (int i = 0; i < max_elements; i++) { mas[i] = new nest(); } /* first = new nest(0); * nest curr = first; * for (int i = 1; i < max_elements; i++) * { * curr.next = new nest(i); * curr.next.prev = curr; * curr = curr.next; * } * curr.next = first; * first.prev = curr;*/ }
public nest find(string login) /*spisok_tariph.nest tariph*///исправить, циклится { //nest curr = first; int hash = get_hash(login); nest start = table[hash]; if (start == null) { return(null); } else { if (start.login == login) { return(start); } else { nest temp = start.next; while (temp != start) { if (temp.login == login) { return(temp); } else { temp = temp.next; } } } return(null); } /*if (curr == null) * { * return null; * } * else if (hash == curr.hash) * { * while(curr!=null) * { * comparisons++; * if (curr.login == login) * return curr; * * curr = curr.chain_next; * } * return null; * } * else * { * //nest check = first; * curr = curr.next; * while (curr != first) * { * if (curr.hash==hash) * { * while(curr!=null) * { * comparisons++; * if (curr.login == login) * return curr; * curr = curr.chain_next; * } * return null; * * } * curr = curr.next; * } * * return null; * }*/ }