2019년 6월 4일 화요일

[OpenSource] DoubleLinkedList Template

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

struct address {
    char name[40];
    char zip[40];
    struct address *next;
    struct address *prior;
} list_entry;

struct address* start;
struct address* last;

struct address* store(i, top)
struct address* i;
struct address* top;
{

    return start;

}

struct address* find(char* name)
{
    struct address* info;


    return NULL;
}

void delete(void)
{
    struct address* info;
 
}

void display()
{
    struct address *top;

    top =  start;
    while(top)
    {
        printf("Name: %s, Zip: %s\n", top->name, top->zip);
        top = top->next;
    }
}

int main(void)
{
    struct address* info;
 
    info = (struct address *)malloc(sizeof(list_entry));
    // Check return value
    if (!info) {
       printf("Out of memory!!\n");
       return 0;
    }
       
    strcpy(info->name, "Tom");
    strcpy(info->zip, "613");

    start = store(info, start);

    info = (struct address *)malloc(sizeof(list_entry));
    // Check return value
    if (!info) {
       printf("Out of memory!!\n");
       return 0;
    }
       
    strcpy(info->name, "John");
    strcpy(info->zip, "713");

    start = store(info, start);

    display();

    delete();

    display();
   
    return 0;
}