void main() { element_type e; node_ptr L, P, xp, xl; int i, n, k; initialize(&L); initialize(&P); printf("\nNhap vao cac phan tu cua danh sach (-1 de ket thuc) : "); do { scanf("%d", &e); if (e != -1) insert_after(e, &L); } while (e != -1); printf("\nNhap vao cac gia tri chi thu tu can lay trong danh sach L (-1 de ket thuc) : "); do { scanf("%d", &e); if (e != -1) insert_after(e, &P); } while (e != -1); n = 1; xl = L; xp = P; do { k = xp->element; for (i=0; i<k-n; i++) if (xl) xl = xl->next; if (xl) printf("\nPhan tu thu %d = %d", k, xl->element); xp = xp->next; n = k; } while ((xp != NULL) && (xl != NULL)); getch(); }
bool InstrList_Finger::Finger_check_partern(Instruction * p) { // check the pattern p char buf[140]={0}; strcpy(buf,this->prt_partern(p).toStdString().c_str()); if (finger_compare(buf, finger_if)) p->begin.type = COMP_if; else if (finger_compare(buf, finger_long_if)) // must be placed before if_else p->begin.type = COMP_long_if; else if (finger_compare(buf, finger_if_else)) p->begin.type = COMP_if_else; else if (finger_compare(buf, finger_while)) p->begin.type = COMP_while; else if (finger_compare(buf, finger_dowhile)) { p->begin.type = COMP_do_while; // Special do-while written for the best if (this->Finger_check_partern_for1(p)) { log_prtl("find for1"); p->begin.type = COMP_for1; } } else if (finger_compare(buf, finger_dowhile_2)) p->begin.type = COMP_do_while; else if (finger_compare(buf, finger_for)) { //const char finger_for[] = "0_jmp1_from2_0_from1_0_jxx3_0_jmp2_from3_"; p->begin.type = COMP_for; //Next, let us make some adjustments in 'for' Instruction * p1 = instr_next(m_list,p); // p1 points to a label assert(p1->type == i_Jump); p1 = instr_next(m_list,p1->jmp.target_label); //p1 points to condition if (p1->type == i_Jump && p1->jmp.jmp_type != JMP_jmp && p1->var_r1.type != 0) { VAR* pvar = &p1->var_r1; Instruction * p2 = instr_prev(m_list,p); if (VAR::IsSame(&p2->var_w,pvar)) { m_list.erase(std::find(m_list.begin(),m_list.end(),p2)); INSTR_LIST::iterator insert_iter = std::find(m_list.begin(),m_list.end(),p); // insert after i_CplxBegin Instruction * begin = new Instruction(i_Begin); Instruction * end = new Instruction(i_End); begin->begin.m_end = end; insert_after(m_list,insert_iter,end); insert_after(m_list,insert_iter,p2); insert_after(m_list,insert_iter,begin); } } } else return false; return true; }
int main(){ int t, v_n, m, cost, source, dest, index, count=0, i,j; long long int res; Node *source_n,*dest_n; scanf("%d",&t); while(t--){ scanf("%d%d%d",&v_n,&m,&cost); for( i = 0; i < v_n; i++ ){ vertex[i] = (Node *)malloc(sizeof(Node)); vertex[i]->v = i; vertex[i]->next = NULL; vertex[i]->visited = 0; } for( i = 0; i < m; i++){ scanf("%d%d",&source,&dest); source_n = (Node *)malloc(sizeof(Node)); source_n->v = source; source_n->visited = 0; dest_n=(Node *)malloc(sizeof(Node)); dest_n->v = dest; dest_n->visited = 0; insert_after(vertex[source],dest_n); insert_after(vertex[dest],source_n); } int disconnects = 0; for(i = 0; i < v_n; i++){ vertex[i]->visited = 1; count = 0; for(j = 0; j < v_n; j++){ if(vertex[j]->visited == 0){ count++; dfs(j); } } for( j = 0; j < v_n; j++ ){ vertex[j]->visited = 0; } if(count > 1){ disconnects++; } vertex[i]->visited = 0; } printf("%d\n",cost*disconnects); } return 0; }
int main(){ struct ll_list *list=new_list(1,1); if(list){ int a=5; insert_after(list,list->head,(void *)&a); a=8; insert_after(list,list->head,(void *)&a); insert_after(list,list->head,(void *)&a); ll_print(list);} printf("\nHello\n"); return 0; }
ProgressWindow::ProgressWindow(ContainerWindow &parent) { set(parent, InfoBoxLayout::landscape ? (LPCTSTR)IDD_PROGRESS_LANDSCAPE : (LPCTSTR)IDD_PROGRESS); TCHAR Temp[1024]; _stprintf(Temp, _T("%s %s"), gettext(_T("Version")), XCSoar_Version); set_item_text(IDC_VERSION, Temp); #ifdef WINDOWSPC RECT rc = parent.get_client_rect(); RECT rcp = get_client_rect(); move(rc.left, rc.top, rcp.right - rcp.left, rcp.bottom - rcp.top); #else #ifndef GNAV SHFullScreen(hWnd, SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON|SHFS_HIDESTARTICON); #endif #endif insert_after(HWND_TOP, true); set_range(0, 100); set_step(5); #ifndef ENABLE_SDL ::SetForegroundWindow(hWnd); #endif /* !ENABLE_SDL */ update(); }
int main(int argc, char *argv[]) { int i; struct node *h = NULL; for(i = 0; i < 10; i++) h = insert_last(h, i); print(h); h = reverse(h, NULL); print(h); h = reverse2(h); print(h); h = delete_first(h); print(h); h = delete_last(h); print(h); h = insert_first(h, 11); print(h); h = insert_last(h, 13); print(h); h = insert_after(h, newnode(14), 13); print(h); return 0; }
int main(void) { list *lista; lista = init_list(); if(lista == NULL) { fprintf(stderr,"Can't create de list"); return -1; } push(lista,1); push(lista,2); push(lista,3); push(lista,4); insert_after(lista,3,10); printf("POP: %i\n",pop(lista)); printf("POP: %i\n",pop(lista)); print_list(lista); destroy_list(lista); return 0; }
void insert_at_end(list_t *list, node_t *new_node) { if (!(list->tail)) { //If list is empty _initialize_list(list, new_node); } else { //Otherwise, insert after tail insert_after(list, list->tail, new_node); } }
void test_order() { struct node *item1, *item2, *item3, *ptr; list_initialize(); item1 = insert_after(1, head); item2 = insert_after(2, item1); item3 = insert_after(3, item2); ptr = head; assert(ptr->next == item1); ptr = ptr->next; assert(ptr->key == 1); assert(ptr->next == item2); ptr = ptr->next; assert(ptr->key == 2); assert(ptr->next == item3); printf("+"); }
void SimpleDLL::add_tail_node(DLLNode addition) { if(!tail) { add_head_node(addition); } else { insert_after(tail, addition); } }
int main() { long i; o_t *o; printf("starting \n"); o = create_order(); for(i=100000; i>=0; i-- ) insert_bottom( o, p(i) ); for(i=100001; i< 300007; i+=2 ) { insert_after(o, p(i+1), p(i-1) ); insert_before( o, p(i), p(i+1) ); } printf("inserted 300000 elements. "); for(i = 250000; i < 300007; i++ ) delete_o( o, p(i) ); printf("deleted 50000 elements. "); insert_top( o, p(300006) ); for(i = 250000; i < 300006; i++ ) insert_before( o, p(i) , p(300006) ); printf("reinserted. now testing order\n"); for( i=0; i < 299000; i +=42 ) { if( compare( o, p(i), p(i+23) ) != 1 ) { printf(" found error (1) \n"); exit(0); } } for( i=300006; i >57; i -=119 ) { if( compare( o, p(i), p(i-57) ) != 0 ) { printf(" found error (0) \n"); exit(0); } } printf("finished. no problem found.\n"); }
int ask_position(struct node *newNode) { printf("\nThe linked list is "); int check=display_list(); if(check==1) { printf("\nThe inserted element becomes the first element\n"); head.next=newNode; } else { printf("\nEnter a choice\n1.Insert after an element\n2.Insert before an element\n"); int choice; scanf("%d",&choice); switch(choice) { case 1: { insert_after(newNode); break; } case 2: { insert_before(newNode); break; } default:printf("\nWrong choice.New element not inserted.\n"); } } }
/* * Insert an item in the list, regardless if it is unique * or not. */ void dlist::binary_insert_multiple(void *item, int compare(void *item1, void *item2)) { void *ins_item = binary_insert(item, compare); /* If identical, insert after the one found */ if (ins_item != item) { insert_after(item, ins_item); } }
PyObject * PyWeakref_NewRef(PyObject *ob, PyObject *callback) { PyWeakReference *result = NULL; PyWeakReference **list; PyWeakReference *ref, *proxy; if (!PyType_SUPPORTS_WEAKREFS(ob->ob_type)) { PyErr_Format(PyExc_TypeError, "cannot create weak reference to '%s' object", ob->ob_type->tp_name); return NULL; } list = GET_WEAKREFS_LISTPTR(ob); get_basic_refs(*list, &ref, &proxy); if (callback == Py_None) callback = NULL; if (callback == NULL) /* return existing weak reference if it exists */ result = ref; if (result != NULL) Py_INCREF(result); else { /* Note: new_weakref() can trigger cyclic GC, so the weakref list on ob can be mutated. This means that the ref and proxy pointers we got back earlier may have been collected, so we need to compute these values again before we use them. */ result = new_weakref(ob, callback); if (result != NULL) { get_basic_refs(*list, &ref, &proxy); if (callback == NULL) { if (ref == NULL) insert_head(result, list); else { /* Someone else added a ref without a callback during GC. Return that one instead of this one to avoid violating the invariants of the list of weakrefs for ob. */ Py_DECREF(result); Py_INCREF(ref); result = ref; } } else { PyWeakReference *prev; prev = (proxy == NULL) ? ref : proxy; if (prev == NULL) insert_head(result, list); else insert_after(result, prev); } } } return (PyObject *) result; }
int main (int argc, char *argv[]) { node *t; init_list (); ordered_insert (10); ordered_insert (5); ordered_insert (8); ordered_insert (3); ordered_insert (1); ordered_insert (7); ordered_insert (8); printf ("\nInitial Linked list is "); print_list (head->next); printf ("\nFinding 5 is %ssuccessful", find_node (4) == tail ? "un" : ""); t = find_node (5); printf ("\nFinding 5 is %ssuccessful", t == tail ? "un" : ""); printf ("\nInserting 9 after 5"); insert_after (9, t); print_list (head->next); t = find_node (10); printf ("\nDeleting next last node"); delete_next (t); print_list (head->next); t = find_node (3); printf ("\nDeleting next 3"); delete_next (t); print_list (head->next); printf ("\nInsert node 2 before 3"); insert_node (2, 3); print_list (head->next); printf ("\nDeleting node 2"); if (!delete_node (2)) printf ("\n deleting 2 is unsuccessful"); print_list (head->next); printf ("\nDeleting node 1"); delete_node (1); print_list (head->next); printf ("\nDeleting all node"); delete_all (); print_list (head->next); return 0; }
int LinkedList::insert_sort(Event *item){ if (item == NULL) { return -1; } // If the list is empty add at first position and initialize pointers if(start == NULL) { printf("Adding first item\n"); start = item; tail = item; cur = item; }else{ // Search the list from last position // Find appropriate location for the new event and place it there printf("Inserting \n"); if(cur->schedTime > item->schedTime) { // Search in backward direction printf("In backward direction \n"); while( (cur != start) && (cur->schedTime > item->schedTime)){ cur = cur->prev; } if((cur == start) && cur->schedTime > item->schedTime){ insert_before(start,item); }else{ insert_after(cur,item); } }else{ // Search in forward direction printf("In forward direction \n"); while( (cur != tail) && (cur->schedTime < item->schedTime)){ cur = cur->next; } if((cur == tail) && cur->schedTime < item->schedTime){ printf("Calling after \n"); insert_after(tail,item); }else{ printf("Calling before \n"); insert_before(cur,item); } } } printf("Insertion done \n"); return 0; }
list_node_type *split_free(list_node_type *node, u32int size) { vmm_data_type *node_data = node->data; list_node_type *new_node = get_unused_node(); vmm_data_type *new_node_data = new_node->data; new_node_data->virt_addr = node_data->virt_addr + size; new_node_data->size = node_data->size - size; node_data->size = size; insert_after(vmm_free, node, new_node); return node; }
GSList* g_slist_insert_before (GSList *list, GSList *sibling, gpointer data) { GSList *prev = find_prev_link (list, sibling); if (!prev) return g_slist_prepend (list, data); insert_after (prev, data); return list; }
void main() { int opt; clrscr(); do { clrscr(); printf("\npress 1 for insert beg:"); printf("\npress 2 for insert end:"); printf("\npress 3 for insert after:"); printf("\npress 4 for insert before:"); printf("\npress 5 for delete beg:"); printf("\npress 6 for delete end:"); printf("\nlpress 7 for delete after :"); printf("\npress 8 for delete before:"); printf("\npress 9 for deleter that:"); printf("\npress 10 for delete odd:"); printf("\npress 11 for delete even:"); printf("\npress 12 for sorting:"); printf("\npress 13 for reverse:"); printf("\npress 14 for insert in sorted order ;"); printf("\npress 15 for display"); printf("\nenter the option:"); scanf("%d",&opt); switch(opt) { case 1:insert_beg(&ptr); break; case 2:insert_end(&ptr);break; case 3:insert_after(&ptr);break; case 4:insert_before(&ptr);break; case 5:delete_beg(&ptr); break; case 6:delete_end(&ptr);break; case 7:delete_after(&ptr);break; case 8:delete_before(&ptr);break; /**/ case 9:delete_that(&ptr);break; case 10:delete_alter_odd(&ptr);break; case 11:delete_alter_even(&ptr);break; case 12:sort(&ptr);break; case 13:reverse(&ptr);break; /**/ case 14:insert_sort(&ptr);break; case 15:display(&ptr);break; } getch(); }while(opt!=99); getch(); }
void insert_btw(Dllist *dll, Vertex *inf, Vertex *sup, Vertex *ins, int const LNK) { // root <=> a <=> inf <=> b <=> c <=> d <=> sup <=> e <=> f <=> root // root <=> a <=> inf <=> ins <=> sup <=> e <=> f <=> root insert_after(dll, inf, ins, LNK); Vertex *current = ins ; while (current->links[LNK][FWD] != sup) { rm_after(dll, current, LNK); } }
bool VMMemPointerIterator::insert_record_after(MemPointerRecord* rec) { VMMemRegionEx new_rec; assert(rec->is_allocation_record() || rec->is_commit_record(), "Sanity check"); if (MemTracker::track_callsite()) { new_rec.init((MemPointerRecordEx*)rec); } else { new_rec.init(rec); } return insert_after(&new_rec); }
static PyObject * weakref___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyWeakReference *self = NULL; PyObject *ob, *callback = NULL; if (parse_weakref_init_args("__new__", args, kwargs, &ob, &callback)) { PyWeakReference *ref, *proxy; PyWeakReference **list; if (!PyType_SUPPORTS_WEAKREFS(ob->ob_type)) { PyErr_Format(PyExc_TypeError, "cannot create weak reference to '%s' object", ob->ob_type->tp_name); return NULL; } if (callback == Py_None) callback = NULL; list = GET_WEAKREFS_LISTPTR(ob); get_basic_refs(*list, &ref, &proxy); if (callback == NULL && type == &_PyWeakref_RefType) { if (ref != NULL) { /* We can re-use an existing reference. */ Py_INCREF(ref); return (PyObject *)ref; } } /* We have to create a new reference. */ /* Note: the tp_alloc() can trigger cyclic GC, so the weakref list on ob can be mutated. This means that the ref and proxy pointers we got back earlier may have been collected, so we need to compute these values again before we use them. */ self = (PyWeakReference *) (type->tp_alloc(type, 0)); if (self != NULL) { init_weakref(self, ob, callback); if (callback == NULL && type == &_PyWeakref_RefType) { insert_head(self, list); } else { PyWeakReference *prev; get_basic_refs(*list, &ref, &proxy); prev = (proxy == NULL) ? ref : proxy; if (prev == NULL) insert_head(self, list); else insert_after(self, prev); } } } return (PyObject *)self; }
/* * Insert a new node immediately after +node+, or replace the existing one if its key is a match. */ NODE* replace_insert_after(NODE* node, size_t key, void* val, bool copy, size_t copy_size) { if (node->next && node->next->key == key) { // Should we copy into the current one or free and insert? if (copy) memcpy(node->next->val, val, copy_size); else { NM_FREE(node->next->val); node->next->val = val; } return node->next; } else { // no next node, or if there is one, it's greater than the current key if (copy) { void* val_copy = NM_ALLOC_N(char, copy_size); memcpy(val_copy, val, copy_size); return insert_after(node, key, val_copy); } else { return insert_after(node, key, val); } }
GaugeCDI::GaugeCDI(ContainerWindow &parent) { // start of new code for displaying CDI window StartupStore(TEXT("Create CDI\n")); set(parent, (int)(InfoBoxLayout::ControlWidth * 0.6), (int)(InfoBoxLayout::ControlHeight + 1), (int)(InfoBoxLayout::ControlWidth * 2.8), (int)(InfoBoxLayout::TitleHeight * 1.4)); insert_after(HWND_TOP); set_font(CDIWindowFont); hide(); }
// Native units // Can't paste silence in here because it's used by paste_silence. Edit* Edits::insert_new_edit(int64_t position) { Edit *current = 0; //printf("Edits::insert_new_edit 1\n"); current = split_edit(position); if(current) current = PREVIOUS; //printf("Edits::insert_new_edit 1\n"); Edit *new_edit = create_edit(); //printf("Edits::insert_new_edit 1\n"); insert_after(current, new_edit); new_edit->startproject = position; //printf("Edits::insert_new_edit 2\n"); return new_edit; }
Auto* Autos::insert_auto(int64_t position) { Auto *current, *result; // Test for existence for(current = first; current && !edl->equivalent(current->position, position); current = NEXT) { ; } // Insert new if(!current) { // Get first one on or before as a template for(current = last; current && current->position > position; current = PREVIOUS) { ; } if(current) { insert_after(current, result = new_auto()); result->copy_from(current); } else { current = first; if(!current) current = default_auto; insert_before(first, result = new_auto()); if(current) result->copy_from(current); } result->position = position; // Set curve type result->mode = edl->local_session->floatauto_type; } else { result = current; } return result; }
GSList* g_slist_copy (GSList *list) { GSList *copy, *tmp; if (!list) return NULL; copy = g_slist_prepend (NULL, list->data); tmp = copy; for (list = list->next; list; list = list->next) tmp = insert_after (tmp, list->data); return copy; }
/* * Given a list and a key/value-ptr pair, create a node (and return that node). * If NULL is returned, it means insertion failed. * If the key already exists in the list, replace tells it to delete the old * value and put in your new one. !replace means delete the new value. */ NODE* insert(LIST* list, bool replace, size_t key, void* val) { NODE *ins; if (list->first == NULL) { // List is empty //if (!(ins = malloc(sizeof(NODE)))) return NULL; ins = NM_ALLOC(NODE); ins->next = NULL; ins->val = val; ins->key = key; list->first = ins; return ins; } else if (key < list->first->key) { // Goes at the beginning of the list //if (!(ins = malloc(sizeof(NODE)))) return NULL; ins = NM_ALLOC(NODE); ins->next = list->first; ins->val = val; ins->key = key; list->first = ins; return ins; } // Goes somewhere else in the list. ins = find_nearest_from(list->first, key); if (ins->key == key) { // key already exists if (replace) { nm_list_storage_completely_unregister_node(ins); NM_FREE(ins->val); ins->val = val; } else { NM_FREE(val); } return ins; } else { return insert_after(ins, key, val); } }
Auto* Autos::insert_auto(int64_t position, Auto *templ) { Auto *current, *result; // Test for existence for(current = first; current && !edl->equivalent(current->position, position); current = NEXT) { ; } // Insert new if(!current) { // Get first one on or before as a template for(current = last; current && current->position > position; current = PREVIOUS) { ; } if(current) { insert_after(current, result = new_auto()); } else { current = first; if(!current) current = default_auto; insert_before(first, result = new_auto()); } // interpolate if possible, else copy from template result->interpolate_from(0, 0, position, templ); } else { result = current; } return result; }
int main(void) { int i; link head, x; // Population head = new_link(0); x = head; for (i = 1; i < N; ++i) { x = insert_after(x, new_link(i)); } // Traversal for (x = head; x != NULL; x = x->next) { printf("%i\n", x->item); } return 0; }