RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
list函数c语言 c语言有list吗

C语言中的list是指什么?求一个简单的list代码

C语言中没有list

创新互联是一家专注于成都网站建设、网站制作与策划设计,博乐网站建设哪家好?创新互联做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:博乐等地区。博乐做网站价格咨询:13518219792

list是C++中的一个类

具体使用可以从网上查一下,有很多应用

C语言中creatlist的用法

1、createlist不是库函数,一般是数据结构中实现新建一个链表的自定义函数。因此没有什么用法好说的,关键是看自己怎么定义。

2、例程:

NODE *creatlist(int a[])

{ NODE *h,*p,*q;int i;

h=(NODE *)malloc(sizeof(NODE));

h-next=NULL;

for(i=0;iN;i++)

{q=(NODE *)malloc(sizeof(NODE));

q-data=a[i];

q-next=NULL;

if(h-next==NULL) h-next=p=q;

else {p-next=q;p=q;}     }

return h;

}

编写C语言函数insert_list完成将给定的数据插入到单链表的指定位置上

s-data=y;

写反了。

void insert_list(list *head,int i,int y)

{

list *p,*s;int j=0;

p=head;

do

{

p=p-next;

j++;

}while(ji-1);

if(j==i-1)

{

s=(list *)malloc(sizeof(list));

/* 这里写反了 y=s-data; */

s-data=y;

s-next=p-next;

p-next=s;

}

}

如何用C语言或C++实现一个List类?

C语言没有类的概念。C++有现成的List类, #includelist即可。

如果要自己实现可以参考C++数据结构的书籍,是最基本的练习。

这里实现一个简单的例程,请参考:

#include iostream

#include fstream

#include stdlib.h

#include string.h

using namespace std;

#includestdio.h

#includestring

#include "math.h"

templateclass T class List{

public:

List()  //构造函数

{

pFirst = NULL;

}

void Add(T t)  //在Link表头添加新结点

{

if(pFirst == NULL)

{

pFirst = new Node;

*(pFirst-pT) = t;

}

else

{

Node* pNewNode = new Node;

*(pNewNode-pT) = t;

pNewNode-pNext = pFirst;

pFirst = pNewNode;

}

}

void Remove(T t) //在Link中删除含有特定值的元素

{

Node* pNode = pFirst;

if(*(pNode-pT) == t)

{

pFirst = pFirst-pNext;

delete pNode;

return;

}

while(pNode != NULL)

{

Node* pNextNode = pNode-pNext;

if(pNextNode!=NULL)

{

if(*(pNextNode-pT) == t)

{

pNode-pNext = pNextNode-pNext;

delete pNextNode;

return;

}

}

else

return;//没有相同的

pNode = pNode-pNext;

}

}

T* Find(T t)  //查找含有特定值的结点

{

Node* pNode = pFirst;

while(pNode != NULL)

{

if(*(pNode-pT) == t)

{

return pNode-pT;

}

pNode = pNode-pNext;

}

return NULL;

}

void PrintList()  // 打印输出整个链表

{

if(pFirst == NULL)

{

cout"列表为空列表!"endl;

return;

}

Node* pNode = pFirst;

while(pNode != NULL)

{

cout*(pNode-pT)endl;

pNode = pNode-pNext;

}

}

~List()

{

Node* pNode = pFirst;

while(pNode != NULL)

{

Node* pNextNode = pNode-pNext;

delete pNode;

pNode = pNextNode;

}

}

protected:

struct Node{

Node* pNext;

T* pT;

Node()

{

pNext = NULL;

pT = new T;

}

~Node()

{

delete pT;

}

};

Node *pFirst;        //链首结点指针

};

class Student

{

public:

char id[20];    //学号

char name[20];    //姓名

int age;    //年龄

Student()

{

}

~Student()

{

}

Student(const char* pid, const char* pname, int _age)

{

strcpy(id, pid);

strcpy(name, pname);

age = _age;

}

bool operator==(const Student stu)

{

return strcmp(id, stu.id) == 0  strcmp(id, stu.id) == 0  age==stu.age;

}

Student operator=(const Student stu)

{

strcpy(id, stu.id);

strcpy(name, stu.name);

age = stu.age;

}

friend ostream operator (ostream out,const Student stu);

};

ostream  operator (ostream out,const Student stu)

{

out"id:"stu.id"\tname:"stu.name"\tage:"stu.ageendl;

}

int main()

{

ListStudent stuList;

cout"添加学生前:"endl;

stuList.PrintList();

Student stu1("1", "张三", 18);

Student stu2("2", "李四", 18);

Student stu3("3", "王五", 18);

Student stu4("4", "至尊宝", 18);

Student stu5("5", "猪八戒", 18);

Student stu6("6", "唐僧", 18);

Student stu7("7", "沙和尚", 18);

Student stu8("8", "观音", 18);

stuList.Add(stu1);

stuList.Add(stu2);

stuList.Add(stu3);

stuList.Add(stu4);

stuList.Add(stu5);

stuList.Add(stu6);

stuList.Add(stu7);

stuList.Add(stu8);

cout"添加学生后:"endl;

stuList.PrintList();

Student stu11("1", "张三", 18);

Student* pStu = stuList.Find(stu11);

cout"查找到的同学是:"*pStu;

stuList.Remove(stu11);

cout"\n\n删除第一个后:"endl;

stuList.PrintList();

return 0;

}


网站标题:list函数c语言 c语言有list吗
URL网址:http://scyingshan.cn/article/dodigjc.html