#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct _stack
{
struct _stack* prev;
struct _stack* next;
int value;
}
stack;
void push( int data );
void pop(void);
stack *temp = NULL;
stack *first = NULL;
stack *real_first = NULL;
int main(void)
{
push(22);
push(32);
push(42);
push(52);
push(4);
push(15);
push(3453);
pop();
pop();
temp = real_first;
while (true)
{
if (temp == NULL)
break;
temp = temp->next;
}
temp = real_first;
while (temp != NULL)
{
real_first = real_first->next;
temp = real_first;
}
return 0;
}
void push( int data)
{
stack
*newptr
= malloc(sizeof(stack
)); if (newptr == NULL)
{
return;
}
newptr->value = data;
newptr->prev = NULL;
newptr->next = NULL;
if (first == NULL)
{
first = newptr;
real_first = first;
}
else
{
newptr->prev = first;
first->next = newptr;
first = newptr;
}
return;
}
void pop(void)
{
if ( real_first == NULL || first == NULL)
return;
else if (real_first->next == NULL )
{
real_first = NULL;
return;
}
else
{
real_first = real_first->next;
real_first->prev = NULL;
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0ZGJvb2wuaD4KCgp0eXBlZGVmIHN0cnVjdCBfc3RhY2sKICAgIHsKICAgICAgICAKICAgICAgICBzdHJ1Y3QgX3N0YWNrKiBwcmV2OwogICAgICAgIHN0cnVjdCBfc3RhY2sqIG5leHQ7CiAgICAgICAgaW50IHZhbHVlOwogICAgICAgIAogICAgfSAKICAgIHN0YWNrOyAKCnZvaWQgcHVzaCggaW50IGRhdGEgKTsKdm9pZCBwb3Aodm9pZCk7CnN0YWNrICp0ZW1wID0gTlVMTDsKc3RhY2sgKmZpcnN0ID0gTlVMTDsKc3RhY2sgKnJlYWxfZmlyc3QgPSBOVUxMOwoKCmludCBtYWluKHZvaWQpCnsKICAgIAoKICAgIHB1c2goMjIpOwogICAgcHVzaCgzMik7CiAgICBwdXNoKDQyKTsKICAgIHB1c2goNTIpOwogICAgcHVzaCg0KTsKICAgIHB1c2goMTUpOwogICAgcHVzaCgzNDUzKTsKICAgIHBvcCgpOwogICAgcG9wKCk7CiAgIAogICAgdGVtcCA9IHJlYWxfZmlyc3Q7CiAgICAKICAgIHdoaWxlICh0cnVlKQogICAgeyAgIAogICAgICAgIGlmICh0ZW1wID09IE5VTEwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIAogICAgICAgIHByaW50ZigiJWkgIiwgdGVtcCAtPnZhbHVlKTsKICAgICAgICB0ZW1wICA9IHRlbXAtPm5leHQ7CiAgICAgICAKICAgIH0KICAgIAogICAgdGVtcCA9IHJlYWxfZmlyc3Q7CiAgICAKICAgICB3aGlsZSAodGVtcCAhPSBOVUxMKQogICAgeyAgIAogICAgICAgIHJlYWxfZmlyc3QgPSByZWFsX2ZpcnN0LT5uZXh0OwogICAgICAgIGZyZWUodGVtcCk7CiAgICAgICAgdGVtcCAgPSByZWFsX2ZpcnN0OwogICAgICAgCiAgICB9CiAgICAKICAgIAogICAgcHJpbnRmKCJcbiIpOwogICAgcmV0dXJuIDA7Cn0KCgoKCgp2b2lkIHB1c2goIGludCBkYXRhKQp7CiAgICBzdGFjayAqbmV3cHRyID0gIG1hbGxvYyhzaXplb2Yoc3RhY2spKTsKICAgIGlmIChuZXdwdHIgPT0gTlVMTCkKICAgIHsKICAgICAgICByZXR1cm47CiAgICB9CiAgICAKICAgIG5ld3B0ci0+dmFsdWUgPSBkYXRhOwogICAgCiAgICBuZXdwdHItPnByZXYgPSBOVUxMOwogICAgCiAgICBuZXdwdHItPm5leHQgPSBOVUxMOwogICAgaWYgKGZpcnN0ID09IE5VTEwpCiAgICB7CiAgICAgICAgZmlyc3QgPSBuZXdwdHI7CgogICAgICAgIHJlYWxfZmlyc3QgPSBmaXJzdDsKICAgICAgICAKICAgIH0KICAgIAogICAgZWxzZQogICAgeyAgIAogICAgICAgIAogICAgICAgIG5ld3B0ci0+cHJldiA9IGZpcnN0OwogICAgICAgIAogICAgICAgIGZpcnN0LT5uZXh0ID0gbmV3cHRyOwogICAgCiAgICAgICAgZmlyc3QgPSBuZXdwdHI7CiAgICAgICAgCiAgICB9CiAgICAKICAgIHJldHVybjsgIAp9CiAgICAKCnZvaWQgcG9wKHZvaWQpCnsgICAKICAgIAogICAgCiAgICBpZiAoIHJlYWxfZmlyc3QgPT0gTlVMTCB8fCBmaXJzdCA9PSBOVUxMKQogICAgICAgIHJldHVybjsKICAgIAogICAgZWxzZSBpZiAocmVhbF9maXJzdC0+bmV4dCA9PSBOVUxMICkKICAgIHsgICAKICAgICAgICAKICAgICAgICAKICAgICAgICBmcmVlKCByZWFsX2ZpcnN0KTsKICAgICAgICByZWFsX2ZpcnN0ID0gTlVMTDsKICAgICAgICAKICAgICAgICByZXR1cm47CiAgICB9CiAgICBlbHNlCiAgICB7CiAgICAgICAgCgogICAgcmVhbF9maXJzdCA9IHJlYWxfZmlyc3QtPm5leHQ7IAogICAgZnJlZShyZWFsX2ZpcnN0LT5wcmV2KTsKICAgIHJlYWxfZmlyc3QtPnByZXYgPSBOVUxMOwogICAgfQogICAgCn0=