数据结构代码含义 求解答

#include "stdio.h"
#include "malloc.h"

int StrLen(const char*pData)
{
int i = 0;
if (pData == NULL)
{
return 0;
}
while (1)
{
if (*(pData + i) != 0)
{
++i;
}else
{
break;
}
}
return i;
}

char *StrCopy(char *pTo,const char *pFrom)
{
int i = 0;
if (pTo == NULL || pFrom == NULL)
{
return NULL;
}
while (1)
{
if ((*(pTo + i) = *(pFrom + i)) != 0)
{
++i;
}else
{
break;
}
}
return pTo;
}

int StrCmp(const char *pFirst,const char *pSecond)
{
int lenF,lenS,i,dis;
if (pFirst == NULL || pSecond == NULL)
{
return NULL;
}
lenF = StrLen(pFirst);
lenS = StrLen(pSecond);

if (lenF > lenS)
{
for (i = 0; i < lenS; ++i)
{
dis = *(pFirst + i) - *(pSecond + i);
if (dis != 0)
{
return dis;
}
}
return 1;
}else if (lenF < lenS)
{
for (i = 0; i < lenF; ++i)
{
dis = *(pFirst + i) - *(pSecond + i);
if (dis != 0)
{
return dis;
}
}
return -1;
}else
{
for (i = 0; i < lenF; ++i)
{
dis = *(pFirst + i) - *(pSecond + i);
if (dis != 0)
{
return dis;
}
}
return 0;
}
return 0;
}

typedef struct SibTreeNode
{
char data[50];
int valid;
int year;
int month;
int day;
int hour;
int minute;
int second;
int sonmulu;
int sonfile;
struct SibTreeNode * parent;
struct SibTreeNode *firstChild;
struct SibTreeNode *nextSibling;
}SibTreeNode;

typedef struct
{
SibTreeNode *root;
int size;
}SibTree;

typedef SibTreeNode *QueueDataType;

typedef struct
{
QueueDataType queue [50];
int front;
int rear;
int count; /* 队列的当前表长 */
} SeqCQueue;

//初始化
void QueueInitiate(SeqCQueue *Q)
{
Q->front=0;
Q->rear=0;
Q->count=0;
}

//判断队列非空
int QueueNotEmpty(SeqCQueue Q)
{
if(Q.count!=0) return 1;
else return 0;
}

//入队列
int QueueAppend(SeqCQueue *Q,QueueDataType x)
{
if(Q->count>0 && Q->rear==Q->front)
{
printf("队列已满无法插入!\n");
return 0;
}
else
{
Q->queue[Q->rear]=x;
Q->rear=(Q->rear+1)%50;
Q->count++;
return 1;
}
}
//出队列
int QueueDelete(SeqCQueue *Q,QueueDataType *x)
{
if(Q->count==0)
{
printf("队列已空无数据元素出队列!\n");
return 0;
}
else
{
*x=Q->queue[Q->front];
Q->front=(Q->front+1)%50;
Q->count--;
return 1;
}
}
//取对头数据元素
int QueueGet(SeqCQueue *Q,QueueDataType *x)
{
if(Q->count==0)
{
printf("队列已空无数据元素出队列!\n");
return 0;
}
else
{
*x=Q->queue[Q->front];
return 1;
}
}

#include <stdio.h>  在使用标准函数库中的输入输出函数时,编译系统要求程序提供有关的信息(例如对这些输入输出函数的声明),#include<stdio.h>的作用就是用来提供这些信息的,stdio.h是C编译系统提供的一个文件名,stdio是“standard input & output”的缩写,即有关标准输入输出的信息。   在程序中用到系统提供的标准函数库中的输入输出函数时,应在程序的开头写上一行:#include"stdio.h"或者是#include<stdio.h>,这样才能调用库函数。
头文件 声明
例如:
#include <stdio.h>
#include <string.h>
#include<malloc.h>//
main()
{
char c[11]={"wang"},*str2;//用指针 ..
str2=(char*)malloc(sizeof(char));//这里要用到 malloc 申请空间
gets(str2);
if(strcmp(c,str2)==0)
printf("对了");
else
printf("错了");
}
解决方法

C/C++ code
int mystrlen(const char a[]){ if( 0==a[0]) return 0; else return 1+ mystrlen(a+1);}int main() { printf("%d\n" , mystrlen( "abcdef" ) ); return 0;}

C/C++ code
int strlen(const char str[]){ int nlen = 0; const char *p = str; while (p && *p++) nlen++; return nlen;}

int strlen(const char *str)
{
int i =0;
while(*str++) i++;
return i;
}

C/C++ codeintmystrlen(constchara[])
{if(0==a[0])return0;elsereturn1+mystrlen(a+1);

}intmain()
{
printf("%d\n", mystrlen("abcdef") );return0;
}

好像经常有人问关于strlen, strcpy, strcat之类的函数如何实现的问题。 大家都对库函数这么好奇?
为什么其他的库函数就很少人问起呢?

比如说printf, sqrt, sin之类的函数怎么实现的。

int mystrlen(const char a[])
{
int i = 0;
const char *p = a;
while(p && *p++)
i++;
return i;
}

函数原型?应该说是函数定义吧:

C/C++ code
#include <stdio.h>int strlen(const char a[]){ if(*a=='\0') return 0; else return 1+ strlen(a+1);}int main() { printf("%d\n" , strlen( "test" ) ); return 0;}

说明一下:不用系统函数,那就只能用递归了。

return sizeof(str) - 1;

C/C++ code
size_t __cdecl strlen ( const char * str ){ const char *eos = str; while( *eos++ ) ; return( (int)(eos - str - 1) );}

VC 6.0中的

int strlen(const char *str)
{
assert(str!=NULL);
int len=0;
while((*str++)!='\0')
{ len++;}
return len;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-01-14
前三个是库函数的具体实现,就不赘述了;
后面依次是 线索二叉树节点的定义、线索二叉树的定义
队列的定义和实现:包括初始化、判空、入队、出队、取队头数据元素等队列操作。
------------
总的来说就是一堆函数和结构体的定义本回答被网友采纳