Untitled
unknown
plain_text
2 years ago
701 B
8
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) {
if(STACK_top(s1) == search) {
flag = 1; //hemos encontrado el libro que queremos. tengo que QUITARLO y reemplazarlo por uno nuevo!
}else {
STACK_push(s2, STACK_top(s1));
STACK_pop(s1);
}
}
if(flag) {
STACK_pop(s1);
STACK_push(s1,newBook);
while(!STACK_isEmpty(*s2)) {
STACK_push(s1, STACK_top(s2));
STACK_pop(s2);
}
printf("Replace successfully!!!");
}
}Editor is loading...