08.11.2014 Views

c_kitap

c_kitap

c_kitap

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C ve Sistem Programcıları Derneği - C Ders Notları - Necati Ergin<br />

Aşağıdaki programda bir tekli bağlı liste oluşturuluyor.<br />

/********** datelist.h **************************/<br />

#include "date.h"<br />

typedef struct tagNode {<br />

Date date;<br />

struct tagNode *pnext;<br />

}Node;<br />

typedef struct {<br />

Node *pstart;<br />

Node *pend;<br />

size_t size;<br />

}*ListHandle;<br />

ListHandle openlist(void);<br />

void closelist(ListHandle);<br />

void push_front(ListHandle handle);<br />

void push_back(ListHandle handle);<br />

void display_list(ListHandle handle);<br />

void pop_front(ListHandle handle);<br />

void pop_back(ListHandle handle);<br />

void remove_date(const Date *);<br />

void clear_list(ListHandle handle);<br />

size_t get_size(ListHandle handle);<br />

/********** datelist.c **************************/<br />

PRIVATE Node *create_node(void);<br />

PRIVATE void free_nodes(Node *p);<br />

/*************************************************************************/<br />

PRIVATE void free_nodes(Node *p)<br />

{<br />

Node *temp;<br />

while (p) {<br />

temp = p;<br />

p = p->pnext;<br />

free(temp);<br />

}<br />

}<br />

/*************************************************************************/<br />

PRIVATE Node *create_node(void)<br />

{<br />

Node *pd = (Node *)malloc(sizeof(Node));<br />

if (!pd) {<br />

printf("cannot allocate memory!\n");<br />

exit(EXIT_FAILURE);<br />

}<br />

return pd;<br />

}<br />

/*************************************************************************/<br />

PUBLIC ListHandle openlist(void)<br />

{<br />

ListHandle pd = (ListHandle)malloc(sizeof(*pd));<br />

if (!pd) {<br />

printf("cannot allocate memory!\n");<br />

exit(EXIT_FAILURE);<br />

}<br />

pd->pstart = pd->pend = NULL;<br />

pd->size = 0;<br />

407

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!