首页 > 代码库 > 判断两条线段是否相交

判断两条线段是否相交

#define _CRT_SECURE_NO_WARNINGS
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
char **sortArray1Array2_01(char **pArray1, int nArray1Num, char(*pArray2)[30], int nArray2Num, int *nArray3Num)
{
	//第一维
	int length = nArray1Num + nArray2Num;//总大度...
	int i = 0, j = 0; int k = 0;

	char **pTmp = (char **)malloc((length)*sizeof(char *)); //分配行数//就是分配多少个字符串。
	// char* pTmp[Array1Num + nArray2Num]    char ptmp[][]//感觉可以这么说么。分配2维的大小
	for (i = 0; i < length; i++)
	{
		pTmp[i] = (char*)malloc(sizeof(char)* 30);      //分配列数 //给列数分配大小; 每个字符串的长度;
		memset(pTmp[i], 0, sizeof(char)* 30);            
	}

	for (i = 0; i < nArray1Num; i++)             //把第一个字符串里面的内容copy到  ptmp
	{
		strcpy(pTmp[i], pArray1[i]);
	}

	for (k = 0; k < nArray2Num; i++, k++) //往后面继续叠加
	{
		strcpy(pTmp[i], pArray2[k]);
	}

	for (i = 0; i < length; i++)          //选择法排序
	{
		for (j = i + 1; j<length; j++)
		{
			if (strcmp(pTmp[i], pTmp[j])>0)      //交换;
			{
				char tmp[30] = { 0 };
				strcpy(tmp, pTmp[i]);
				strcpy(pTmp[i], pTmp[j]);
				strcpy(pTmp[j], tmp);
			}
		}
	}
	*nArray3Num = length;     //长度甩出去;

	return pTmp;      //地址甩出去。

}
void free_arr(char** arr, int length)      //释放。
{
	int i = 0;
	if (arr == NULL)
	{
		return;
	}
	for (i = 0; i < length; i++)
	{
		if (arr[i] != NULL)
		{
			free(arr[i]);
		}
	}
	if (arr != NULL)
	{
		free(arr);
	}
}
void main()
{

	int i = 0;
	char **pArray3 = NULL;
	int nArray3Num = 0;
	//指针数组
	char *array1[] = { "bbbbb", "aaaaa", "ccccc", "22222", "11111", "44444" };

	//二维数组
	char array2[10][30] = { "zzzz", "yyyy", "333333" };

	pArray3 = sortArray1Array2_01(array1, 6, array2, 3, &nArray3Num); //甩出地址给pArray3.
	if (pArray3 == NULL)
	{
		printf("func sortArray1Array() err\n");
	}

	for (i = 0; i < nArray3Num; i++)
	{
		printf("%s \n", pArray3[i]);
	}
	if (pArray3 != NULL)
	{
		free_arr(pArray3, nArray3Num);
		pArray3 = NULL;
	}
	system("pause");

}


判断两条线段是否相交