first commit
This commit is contained in:
10
include/ListNode.h
Normal file
10
include/ListNode.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef LINKNODE_H
|
||||
#define LINKNODE_H
|
||||
|
||||
struct ListNode
|
||||
{
|
||||
int val;
|
||||
struct ListNode *next;
|
||||
};
|
||||
|
||||
#endif // LINKNODE_H
|
||||
72
include/Stack.h
Normal file
72
include/Stack.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef STACK_H
|
||||
#define STACK_H
|
||||
#include <stdlib.h>
|
||||
|
||||
struct stack_t
|
||||
{
|
||||
struct stack_node_t *head;
|
||||
struct stack_node_t *rear;
|
||||
|
||||
void (*enqueue)(struct stack_t *, int);
|
||||
void (*dequeue)(struct stack_t *, int *);
|
||||
void (*delete)(struct stack_t *);
|
||||
};
|
||||
|
||||
struct stack_node_t
|
||||
{
|
||||
int data;
|
||||
struct stack_node_t *next;
|
||||
};
|
||||
|
||||
void enqueue(struct stack_t *self, int v)
|
||||
{
|
||||
struct stack_node_t *n = (struct stack_node_t *)malloc(sizeof(struct stack_node_t));
|
||||
n->data = v;
|
||||
n->next = NULL;
|
||||
|
||||
if (!self->head)
|
||||
{
|
||||
self->head = self->rear = n;
|
||||
return;
|
||||
}
|
||||
|
||||
self->rear->next = n;
|
||||
self->rear = n;
|
||||
}
|
||||
|
||||
void dequeue(struct stack_t *self, int *r)
|
||||
{
|
||||
struct stack_node_t *p = self->head;
|
||||
while (p)
|
||||
{
|
||||
if (p->next == self->rear)
|
||||
break;
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
*r = self->rear->data;
|
||||
free(self->rear);
|
||||
p->next = NULL;
|
||||
self->rear = p;
|
||||
}
|
||||
|
||||
void delete(struct stack_t *self)
|
||||
{
|
||||
while (self->head)
|
||||
{
|
||||
struct stack_node_t *tmp = self->head;
|
||||
self->head = self->head->next;
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
self->head = NULL;
|
||||
self->rear = NULL;
|
||||
}
|
||||
|
||||
void init_stack(struct stack_t *s)
|
||||
{
|
||||
s->head = NULL;
|
||||
s->rear = NULL;
|
||||
}
|
||||
|
||||
#endif // STACK_H
|
||||
11
include/TreeNode.h
Normal file
11
include/TreeNode.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef TREENODE_H
|
||||
#define TREENODE_H
|
||||
|
||||
struct TreeNode
|
||||
{
|
||||
int val;
|
||||
struct TreeNode *left;
|
||||
struct TreeNode *right;
|
||||
};
|
||||
|
||||
#endif // TREENODE_H
|
||||
58
include/leetcode/utils.h
Normal file
58
include/leetcode/utils.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef FREE
|
||||
#define FREE(p) \
|
||||
do \
|
||||
{ \
|
||||
free(p); \
|
||||
p = NULL; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef MALLOC
|
||||
#define MALLOC(p, s, err) \
|
||||
do \
|
||||
{ \
|
||||
p = malloc(s); \
|
||||
if (p == NULL) \
|
||||
goto err; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef REALLOC
|
||||
#define REALLOC(p, s, err) \
|
||||
do \
|
||||
{ \
|
||||
p = realloc(p, s); \
|
||||
if (p == NULL) \
|
||||
goto err; \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CALLOC
|
||||
#define CALLOC(p, s, err) \
|
||||
do \
|
||||
{ \
|
||||
p = calloc(s, 1); \
|
||||
if (p == NULL) \
|
||||
goto err; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef ASSERT
|
||||
#define ASSERT(cond, except, err) \
|
||||
do \
|
||||
{ \
|
||||
if (cond != except) \
|
||||
{ \
|
||||
printf("assert failed! at line: %d in %s\n", __LINE__, __FUNCTION__); \
|
||||
goto err; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#endif // UTILS_H
|
||||
Reference in New Issue
Block a user