void add_link(char *name, link *item, link *parent){ link *menu = NULL; menu = new link; if(menu == NULL) { std::cout << "Error" << std::endl; return NULL; } strcpy_s(menu->name, name); link *ptr = item; int count = 0; if(parent == NULL) { if(ptr == NULL) { menu->next = NULL; menu->previous = NULL; } else { link *last = NULL; while(ptr != NULL) { last = ptr; ptr = ptr->next; } menu->next = NULL; menu->previous = last; } } ptr = menu;}
link* add_link(char *name, link *item, link *parent){ link *menu = NULL; menu = new link; if(menu == NULL) { std::cout << "Error" << std::endl; return NULL; } strcpy_s(menu->name, name); link *ptr = item; int count = 0; if(parent == NULL) { if(ptr == NULL) { menu->next = NULL; menu->previous = NULL; //ptr = menu; } else { link *last = NULL; while(ptr != NULL) { last = ptr; ptr = ptr->next; } menu->next = NULL; menu->previous = last; } } ptr = menu; return ptr;}
C++ (Qt)void Add2List(link * item, link * prevItem, link *& head, link *& tail){ item->previous = prevItem; item->next = prevItem ? prevItem->next : head; if (item->next) item->next->previous = item; else tail = item; if (!prevItem) head = item; else prevItem->next = item;}
void add_link(char *name, link **item, link *parent){ link *menu = NULL; menu = new link; if(menu == NULL) { std::cout << "Error" << std::endl; return; } strcpy_s(menu->name, name); link *ptr = *item; if(parent == NULL) { if(ptr == NULL) { menu->next = NULL; menu->previous = NULL; *item = menu; } else { link *last = NULL; while(ptr != NULL) { last = ptr; ptr = ptr->next; } menu->next = NULL; menu->previous = last; last->next = menu; } }}
C++ (Qt)// использованиеmenu = AppendMenu(menu, CreateItem("name")); // добавление в хвостlink * AppendMenu( link * menu, link * item ){ item->previous = item->next = 0; // это лучше сделать в CreateItem if (!menu) return item; link * last = menu; while (last->next) last = last->next; last->next = item; item->previous = last; return menu;}