#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct
{
    int num;
    char *pre_add;
    char *next_add;
} address;

void getaddress( address *add,char *add_head,int x,int i);
void extract(char *add);
int number(char str[20]);


 

int main()
{
    char str[20];
    char *add;
    int i;
    int j;
    int num;
    address *member;
    
    
    for( i=0; i<1000; i++ )
    {
        fgets(str,20,stdin);
        
        if( 0 == strncmp( str, "insert", 6 ) )
        {
            num = number(str);
            getaddress(&member,add,num,i);
        }
        else if( 0 == strncmp( str, "extract", 7 ) )
        {
            extract(add);
        }
        else if( 0 == strncmp( str, "end", 3 ) )
        {
            break;
        }
        else
        {
            //do nothing
        }
    }
    
    //free(getaddA);
    //free(getaddB);
    return 0;
}


void getaddress( address *add,char *add_head,int x,int i)
{
    if( 0 != i)
    {
        address *getaddB = (address*)malloc(sizeof(address));
        
        getaddB->num = x;
        getaddB->pre_add = (char*)add_head;
        add->next_add = (char*)getaddB;
        
        printf("pre_add=%ld,next_add=%ld\n",getaddB->pre_add,add->next_add);
        
    }
    else
    {
        address *getaddA = (address*)malloc(sizeof(address));
        
        getaddA->num = x;
        
        add_head = (char*)add;
        
        printf("add=%p,add_head=%p\n",add,add_head);
    }
    
}

void extract(char *add)
{
    address *max;
    
    max->num = 0;
    
    printf("extract\n");
    
}

int number(char str[20])
{
    long num;
    char strtonum[20];
    int i;
    
    
    for(i=0; i<20; i++)
    {
        strtonum[i] = str[i+7];
        if( '\n' == strtonum[i] )
        {
            break;
        }
    }
    
    num = strtol(strtonum,NULL,0);
    
    return num;
}
