Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
748 B
3
Indexable
void replaceBook(Stack *s1, Stack *s2, int searchCode, int newBookCode) {

    int flag = 0;
    Element search = searchCode;
    Element newBook = newBookCode;

    while(!STACK_isEmpty(*s1) && flag != 1) {

        if(STACK_top(s1) == search) {
            flag = 1; //hemos encontrado el libro que queremos. tengo que QUITARLO y reemplazarlo por uno nuevo!
            STACK_pop(s1);
            STACK_push(s1,newBook);
            break;

        }else {
            STACK_push(s2, STACK_top(s1));
            STACK_pop(s1);
        }

    }

    if(flag == 1) {        

        while(!STACK_isEmpty(*s2)) {
            STACK_push(s1, STACK_top(s2));
            STACK_pop(s2);
        }

        printf("Replace successfully!!!\n"); 
    }

}