jQuery鼠标指针特效

复习单链表-->ubuntu : gcc编译

gcc_manual

参考

1-o 选项:可以指定编译后输出的可执行文件的名称。
如:helloworld.c 编译后指定输出文件名为test,使用方式如下:
    gcc -o test helloworld.c
 
(2-c 选项:只编译C语言代码,不进行汇编连接。
    如 gcc -c helloworld.c 会产生一个叫 helloworld.o 的目标文件。
 
(3-S 选项,编译并产生汇编源文件。
    如 gcc -S helloworld.c 会产生一个 helloworld.s 的汇编源文件。
 
(4-E 选项,只对C源文件进行预处理。
    如 gcc -E helloworld.c 只对C源文件中的宏和预处理进行展开,不编译C源文件。

————————————————


g++ --->1-o :可以指定输出文件名,在编译为目标代码时,这一选项不是可以忽略的。如果没有指定输出文件名,缺省文件名是a.out。
 
(2-c:只编译生成目标文件,不链接。
 
(3-E:只运行 C 预编译器。
 
(4-S:编译并产生汇编源文件。

oneWayList.h

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

/*
单向链表头文件
lomo_t@lomo-unix:~/rubbish_box/list_box$ gcc -o text text.c oneWayList.c 
lomo_t@lomo-unix:~/rubbish_box/list_box$ ./text 
1 2 3 4 5 0 /n
1 2 3 4 5 20 0 /n
3 4 5 20 0 /n
3 4 5 20 /n

*/

typedef int DateType;//重命名int

typedef struct SListNode
{
	DateType data;
	struct SListNode* next;
}SLNode;


void printSL(SLNode *head);

SLNode* createNode(DateType x);//创建一个节点-->头节点?

void backPush(SLNode** head,DateType x);//尾插 

void frontPush(SLNode** head,DateType x);//头插 

void backPop(SLNode** head); //尾删

void frontPop(SLNode** head); //头删

void insertSL(SLNode** head,SLNode* pos ,DateType x);//指定位置插入

void deleteSL(SLNode** head,SLNode* pos);//指定位置删除

//销毁链表
void SListDestroy(SLNode** pphead);

//寻找链表中的结点
SLNode* SListFind(SLNode* phead,DateType x);

//在指定结点后插入
void SListInsertAfter(SLNode* pos, DateType x);

oneWayList.c

#include<stdio.h>
#include<stdlib.h>
#include "oneWayList.h"


SLNode* createNode(DateType x)
{
	SLNode* newnode = (SLNode*)malloc(sizeof(SLNode));
	if(NULL == newnode)
	{
		printf("malloc fail");
		exit(-1);
	}
	
	newnode->data = x;
	newnode->next = NULL;
	return newnode;
}


void backPush(SLNode** head,DateType x)
{
	assert(head);
	SLNode *newnode = createNode(x);
	
	if((*head) == NULL)
	{
		*head = newnode;
	}
	else
	{
		SLNode* cur = *head;
		while(cur->next != NULL)
		{
			cur = cur->next;
		}
		cur->next = newnode;
	}
	
}

void frontPush(SLNode** head,DateType x)
{
	assert(head);
	SLNode *newnode = createNode(x);
	
	newnode->next = *head;
	*head = newnode;
}

void printSL(SLNode *head)
{
	while(head)
	{
		printf("%d ", head->data);
		head = head->next;
	}
	printf("/n");
	
	getchar();
}


void backPop(SLNode** head)
{
	assert(head && *head);
	
	SLNode *end = *head;
	
	if(end->next == NULL)
	{
		free(end);
		*head =NULL;
	}
	else
	{
		while(end->next->next != NULL)
		{
			end = end->next;
		}
		free(end->next);
		end->next = NULL;
	}

}

void frontPop(SLNode** head)
{
	assert(head && *head);
	
	SLNode* code = *head;
	
	*head = code->next;
	free(code);
	code = NULL;
	
	
}


void SListDestroy(SLNode** head)
{

	assert(head);
	
	SLNode* p = *head;
	SLNode* cur = *head;
	
	while(p)
	{
		p=p->next;
		free(cur);
		cur = p;
	}
	*head = NULL;
}


SLNode* SListFind(SLNode* head,DateType x)
{
	while(head)
	{
		if(head->data == x)
		{
			return head;
		}
		head = head->next;
	}
	
	return NULL;
}


void insertSL(SLNode** head,SLNode* pos ,DateType x)
{
	assert(pos && *head);
	SLNode *p = *head;
}


void SListInsertAfter(SLNode* pos, DateType x)
{
	SLNode* newnode = createNode(x);
	
	newnode->next = pos->next;
	pos->next = newnode;
}

//因为头(*pphead)指向第一个结点,为确保删掉第一个结点头的指向得改变,所以得分开讨论删除第一个结点和其他结点。
void deleteSL(SLNode** head,SLNode* pos)
{	
	assert(head);
	SLNode *p = *head;
	
	if(*head == pos)
	{
		frontPop(head);
	}
	else
	{
		while (p->next != pos)
		{
			p = p->next;
		}

		p->next = pos->next;
		free(pos);
	}
	
	
}

text.c

#include <stdio.h>
#include <stdlib.h>
#include "oneWayList.h"


void test()
{
	SLNode *sl = NULL;
	int i = 1;
	
	
	backPush(&sl,1);
	backPush(&sl,2);
	backPush(&sl,3);
	backPush(&sl,4);
	backPush(&sl,5);
	backPush(&sl,0);
	
	//frontPush(sl,1);//测试报错断言
	/*
	frontPush(&sl,1);
	frontPush(&sl,2);
	frontPush(&sl,3);
	frontPush(&sl,4);
	frontPush(&sl,5);
	*/
	
	printSL(sl);
	
	SLNode *pos = SListFind(sl,0);
	
	pos = SListFind(sl,5);
	while(pos)
	{
		SListInsertAfter(pos,20);
		pos = SListFind(pos->next,3);
	}
	printSL(sl);
	
	frontPop(&sl);
	frontPop(&sl);
	printSL(sl);
	backPop(&sl);
	printSL(sl);
}

int main() {

	test();//操作的测试
	return 0;

}
posted @   僵小七  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 凌晨三点救火实录:Java内存泄漏的七个神坑,你至少踩过三个!
点击右上角即可分享
微信分享提示