易截截图软件、单文件、免安装、纯绿色、仅160KB

链表综合操作C版实现程序

决定找时间把数据结构复习下,从链表开始吧。这一知识点虽说并不涉及复杂的算法,不需要费尽头脑去思考来龙去脉,但是要写出完整的程序来,还是要花一些时间的。特别是如果对指针操作不够熟练,极易出错。好久没用C写程序了……
完整代码:
/*
* 单链表基本操作C版实现程序
* 包括插入、删除、查找。
*
* author: wensefu
* date: 10-5-4
*/
#include<stdio.h>
#include<stdlib.h>
/*单链表数据结构定义*/
typedef struct Node
{
int e; //这里简单点,以整型为结点数据域
struct Node * next;
}LNode,*LinkList;
/*相关函数声明*/
bool ListInit(LinkList); //初始化链表
bool ListInsert(int,int,LinkList); //插入 (注:C中没有bool类型)
bool ListDelete(int,LinkList); //删除指定位置结点
int GetElem(LinkList,int); //返回指定位置结点数据域的值
int GetLength(LinkList); //获取链表长度
void print(LinkList); //print
LinkList CreateList(); //建立一个空链表
int main()
{
printf("--------------------------------链表综合操作------------------------------\n\n");

/****先初始化*******/
LinkList l=CreateList();
if(ListInit(l))
{
printf("The linklist now is:>");
print(l);
}

/******执行操作**********/
bool flag=true;
int e,pos;
while(true)
{
if(flag==false)
{
break;
}
printf("请选择操作: 1.插入 2.删除 3.查找 4.退出>");

int choice;
while(true)
{
scanf("%d",&choice);
if(choice<1||choice>4)
{
printf("Input error,try again:>");
}
else
{
break;
}
}
switch(choice)
{
case 1:
printf("input elem and pos>");
scanf("%d%d",&e,&pos);
if(ListInsert(e,pos,l))
{
printf("Insert successful,now the linklist is: ");
print(l);
}
else
{
printf("Insert failed\n");
}
break;
case 2:
printf("input pos to delete>");
scanf("%d",&


相关文档:

C/C++中typedef的用法,告诉你不一样的typedef


<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......

如何理解c和c++ 的复杂类型声明

曾经碰到过让你迷惑不解、类似于int * (* (*fp1) (int) ) [10];这样的变量声明吗?本文将由易到难,一步一步教会你如何理解这种复杂的C/C++声明。
  我们将从每天都能碰到的较简单的声明入手,然后逐步加入const修饰符和typedef,还有函数指针,最后介绍一个能够让你准确地理解任何C/C++声明的“右左法则”。 ......

C测试小程序

C测试小程序
1、                 字符串类
1.1        strstr
功能:查找和获取子串
void test_strstr()
{
        char *str="Borland   Inte ......

c输入输出


格式输出:
printf(格式控制, 输出表列);
%d 十进制数  %md m为指定的宽度 若数据位数小于m,则左端补以空格;若大于m,则按实际位数输出
%ld 长整型数据  %mld 指定字段宽度
%o 八进制整数形式  %mo
%x 十六进制整数形式  %mx
%u unsigned型数据,它也可用%o或%x格式输出
%c 一个字符   ......

c/c++类型

1.分类
 内部类型 和用户定义类型
2.
 整形:bool ,字符型,整形
   true  1                   flase 0
   非零 true              & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号