我的256创作纪念日

机缘

  挺开心的,想到自己未曾写过一些非技术类的博客,恰巧今天刚好也是我的256创作纪念日,就乘着这个日子,写一点自己过去的收获、内心的想法和对未来的展望吧。

  本人不才,只就读于一所民办本科之中,我挺不想说“高考失利”这几个字。在我看来,水平、心态、运气等都会影响到一个人,有的东西是很难用一个词语去进行概括的。当初也是权衡了很多的层面,选择了计算机专业,开始去尝试自学很多东西,也了解到了CSDN,成为CSDN中的一员,也开始尝试去发表自己写的一些拙劣的文章。

  当初发表文章也可能只是为了好玩或者是图个新鲜,感觉自己成为一名博客写手是会挺有成就感的。倏忽而逝,离我发表的第一篇文章也有了256天。


收获

  确实,写博客可以带给我很多东西,在写博客的时候,本身就是对自身知识的补充和提高,写博客也提高自己的专注度,写博客本就是一种心流的过程。每次完成博客并且发表的时候都挺有成就感的。

  也是有了正向反馈,写博客这件事情能够更好的坚持下去。虽然我和别人也有很大的差距,但是继续加油,不断积累,持续努力。
、、


日常

  毕竟是计科专业的,写博客和学习之间也到没有什么冲突,不过希望自己以后也要多多尝试新的东西,多去试错,也要多去接交新的朋友,学习新的东西。

  前段日子去的鸡鸣寺,南京真的是一座很漂亮的城市。


成就

  我自身的水平仍有限,很难说有什么是可以称得上写的好的代码,这里就贴个来自网上学习的各种数据结构实现的代码吧。看到自己能够实现数据结构并且能够以自己期望的方式在内存中储存,好像就在和计算机交流一样,挺有成就感的。(这里水亿点字数)

//链表

#include"SList.h"

void SLTPrint(SLTNode* phead)
{
    
    
	assert(phead);

	/*while (phead)
	{
		printf("%d->", phead->data);
		phead = phead->next;
	}*/

	SLTNode* cur = phead;
	while (cur)
	{
    
    
		printf("%d->", cur->data);
		cur = cur->next;
	}
	printf("NULL\n");
}

SLTNode* BuySLTNode(SLTDataType x)
{
    
    
	SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));
	if (newnode == NULL)
	{
    
    
		perror("malloc fail");
		return NULL;
	}

	newnode->data = x;
	newnode->next = NULL;

	return newnode;
}

void SLTPushBack(SLTNode** pphead, SLTDataType x)
{
    
    
	assert(pphead);

	SLTNode* newnode = BuySLTNode(x);
	
	if (*pphead == NULL)
	{
    
    
		*pphead = newnode;
	}
	else
	{
    
    
		SLTNode* tail = *pphead;
		while (tail->next)
		{
    
    
			tail = tail->next;
		}

		tail->next = newnode;
	}
}

void SLTPushFront(SLTNode** pphead, SLTDataType x)
{
    
    
	assert(pphead);

	SLTNode* newnode = BuySLTNode(x);
	newnode->next = *pphead;
	*pphead = newnode;
}

void SLTPopBack(SLTNode** pphead)
{
    
    
	assert(pphead);
	assert(*pphead);

	if ((*pphead)->next==NULL)
	{
    
    
		free(*pphead);
		*pphead = NULL;
	}
	else
	{
    
    

		SLTNode* tail = *pphead;
		while (tail->next->next != NULL)
		{
    
    
			tail = tail->next;
		}

		free(tail->next);
		tail->next = NULL;
	}
}

void SLTPopFront(SLTNode** pphead)
{
    
    
	assert(pphead);
	assert(*pphead);

	SLTNode* first = *pphead;
	*pphead = first->next;
	free(first);
	first = NULL;
}

SLTNode* SLTFind(SLTNode* phead, SLTDataType x)
{
    
    
	SLTNode* cur = phead;
	while (cur)
	{
    
    
		if (cur->data == x)
		{
    
    
			return cur;
		}

		cur = cur->next;
	}

	return NULL;
}

void SLTInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x)
{
    
    
	assert(pphead);
	assert(pos);

	if (*pphead == pos)
	{
    
    
		SLTPushFront(pphead, x);
	}
	else
	{
    
    
		SLTNode* prev = *pphead;
		while (prev->next != pos)
		{
    
    
			prev = prev->next;
		}

		SLTNode* newnode = BuySLTNode(x);
		prev->next = newnode;
		newnode->next = pos;
	}
}

void SLTErase(SLTNode** pphead, SLTNode* pos)
{
    
    
	assert(pphead);
	assert(pos);

	if (*pphead == pos)
	{
    
    
		SLTPopFront(pphead);
	}
	else
	{
    
    
		SLTNode* prev = *pphead;
		while (prev->next != pos)
		{
    
    
			prev = prev->next;
		}

		prev->next = pos->next;
		free(pos);
	}
}
//栈

void STPrint(ST* ps)
{
    
    
	assert(ps);

	if (ps->top==0)
	{
    
    
		printf("该栈为空栈\n");
	}
	else
	{
    
    
		printf("该栈中的元素为:");
		
		for (int i = 0; i < ps->top; i++)
		{
    
    
			printf("%d ", ps->a[i]);
		}

		printf("\n");
	}
}

void STInit(ST* ps)
{
    
    
	assert(ps);

	STDataType* tmp = (STDataType*)malloc(sizeof(STDataType) * 4);
	if (NULL == tmp)
	{
    
    
		perror("maloc fail");
		return;
	}

	ps->a = tmp;
	ps->capacity = 4;
	ps->top = 0;//top是栈的下一个元素
}

void STDestroy(ST* ps)
{
    
    
	assert(ps);

	free(ps->a);
	//注意让野指针为NULL
	ps->a = NULL;
	ps->capacity = 0;
	ps->top=0;
}

void STPush(ST* ps, STDataType x)
{
    
    
	assert(ps);

	if (ps->capacity == ps->top)
	{
    
    
		STDataType* tmp = (STDataType*)realloc(ps->a, sizeof(STDataType) * ps->capacity * 2);
		if (tmp == NULL)
		{
    
    
			perror("realloc fail");
			return;
		}

		ps->a = tmp;
		ps->capacity *= 2;
	}

	ps->a[ps->top] = x;
	ps->top++;
}

void STPop(ST* ps)
{
    
    
	assert(ps);

	ps->top--;
}

int STSize(ST* ps)
{
    
    
	assert(ps);

	return ps->top;
}

bool STEmpty(ST* ps)
{
    
    
	assert(ps);

	return (ps->top) == 0;
}

STDataType STTop(ST* ps)
{
    
    
	assert(ps);
	assert(!STEmpty(ps));

	return ps->a[ps->top-1];
}
//二叉树

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


typedef int BTDataType;

typedef struct BinaryTreeNode
{
    
    
	BTDataType data;
	struct BinaryTreeNode* left;
	struct BinaryTreeNode* right;
}BTNode;

BTNode* BuyNode(BTDataType x)
{
    
    
	BTNode* node = (BTNode*)malloc(sizeof(BTNode));
	if (NULL == node)
	{
    
    
		perror("malloc fail");
		return;
	}

	node->data = x;
	node->left = NULL;
	node->right = NULL;
	return node;
}

BTNode* CreatTree()
{
    
    
	BTNode* node1 = BuyNode(1);
	BTNode* node2 = BuyNode(2);
	BTNode* node3 = BuyNode(3);
	BTNode* node4 = BuyNode(4);
	BTNode* node5 = BuyNode(5);
	BTNode* node6 = BuyNode(6);
	BTNode* node7 = BuyNode(7);


	node1->left = node2;
	node1->right = node4;
	node2->left = node3;
	node4->left = node5;
	node4->right = node6;
	node2->right = node7;

	return node1;
}

// 二叉树前序遍历
void PreOrder(BTNode* root)
{
    
    
	if (root == NULL)
	{
    
    
		printf("NULL ");
		return;
	}

	printf("%d ", root->data);
	PreOrder(root->left);
	PreOrder(root->right);
}

// 二叉树中序遍历
void InOrder(BTNode* root)
{
    
    
	if (root == NULL)
	{
    
    
		printf("NULL ");
		return;
	}

	InOrder(root->left);
	printf("%d ", root->data);
	InOrder(root->right);
}

// 二叉树后序遍历
void PostOrder(BTNode* root)
{
    
    
	if (root == NULL)
	{
    
    
		printf("NULL ");
		return;
	}

	PostOrder(root->left);
	PostOrder(root->right);
	printf("%d ", root->data);
}

// 二叉树节点个数
int BinaryTreeSize(BTNode* root)
{
    
    
	return root == NULL ? 0 : BinaryTreeSize(root->left) + BinaryTreeSize(root->right) + 1;
}

int BinaryTreeHeight(BTNode* root)
{
    
    
	if (NULL == root)
		return 0;

	int leftHeight = BinaryTreeHeight(root->left);
	int rightHeight = BinaryTreeHeight(root->right);

	return leftHeight > rightHeight ? leftHeight + 1 : rightHeight + 1;
}

// 二叉树叶子节点个数
int BinaryTreeLeafSize(BTNode* root)
{
    
    

}

// 二叉树第k层节点个数
int BinaryTreeLevelKSize(BTNode* root, int k);

// 二叉树查找值为x的节点
BTNode* BinaryTreeFind(BTNode* root, BTDataType x)
{
    
    
	if (root == NULL)
		return NULL;

	if (root->data == x)
		return root;

	int lret = BinaryTreeFind(root->left, x);
	if (lret)
		return lret;

	int rret = BinaryTreeFind(root->right, x);
	if (rret)
		return rret;

	return NULL;
}

int main()
{
    
    
	BTNode* root = CreatTree();
	PreOrder(root);
	printf("\n");

	InOrder(root);
	printf("\n");

	PostOrder(root);
	printf("\n");

	int size = BinaryTreeSize(root);
	printf("该树一共有结点%d:个\n", size);

	int height = BinaryTreeHeight(root);
	printf("该树的树高为:%d\n", height);

	BTNode* ret = BinaryTreeFind(root, 3);
	printf("结点为3的二叉树结点地址为:%p\n", ret);

	return 0;
}

憧憬

  我们无法改变过去,也不能够预知未来,所有我们只能把握当下。对于过去已定的事实,我们无法做出改变。大可不必焦虑,更不必有负罪感,与其关注这种心理状态,不如去做些别的事情,去看一看在收藏夹中但从未点击过的电影,去尝一尝一直很想吃的店铺,来一趟说走就走的旅行…

  希望自己可以把握当下, 做好当前的事情;即使无法卓越,但要不断努力,持续进步,争取在未来看到更好的自己。

  “沉舟侧畔千帆过,病树前头万木春。”

扫描二维码关注公众号,回复: 15996575 查看本文章

猜你喜欢

转载自blog.csdn.net/Crocodile1006/article/details/131164998