c语言中的list
Ⅰ c语言的形参struct list 和 list有什么区别吗
对于结构体类型变量定义,struct list和list在C++中是相同的,都是正确的。
但在C语言中,如果没有经过重定义处理,则会编译报错。如:
typedefstructlist
{
intdata;
structlist*next;
}list;
这样之后,可以使用struct list 或 list 来定义变量了,如:
struct list * link ;
list * link1 ;
Ⅱ C语言线性表中list->last什么意思
你这个应该是 利用数组的连续存储空间顺序存放线性表的各元素 而这个last通常是个标志位 记录数组已经存了多少条数据 如果last赋的初值是-1 那么这个last表示的就是最后一个数组元素的下标 而list是结构体类型的指针(C语言中) 所以list->last就是取last的值 而for(i=0;i<(list->last);i++)的意思就是一个for循环 你要是明白last是什么意思 这句话也应该明白了
Ⅲ C语言:不懂一个结构List中List p是什么意思
typedef PtrTolNode List; //看这句, List就是那个结构体
Ⅳ c语言中的linked list
//list 头文件
#include <stdlib.h>
#include <string.h>
#define NEW (struct node *)malloc(sizeof(struct node))
struct node
{
char name[20];
char tel[9];
struct node *next;
};
/* 创建 linked list */
struct node *create()
{
static struct node *h;
struct node *p,*q;
char name[20];
h = NULL;
printf("name : ");
gets(name);
while(0 != strlen(name))
{
p = NEW;
if(NULL == p)
{
printf("allocation failure \n");
exit(0);
}
strcpy(p->name,name);
printf("tel : ");
gets(p->tel);
p->next = NULL;
if(NULL == h)
h = p;
else
q->next = p;
q = p;
printf("name: ");
gets(name);
}
return h;
}
/* 遍历linked list */
void printlist(struct node *head)
{
struct node *p;
p = head;
while(NULL != p)
{
printf("%s\t%s\n",p->name,p->tel);
p = p->next;
}
}
/* 删除节点 */
struct node *delnode(struct node *head, char *x)
{
struct node *p,*q;
static struct node *h;
if(NULL == head)
{
printf("this is a empty linked list");
return head;
}
p = head;
while(0 != strcmp(x,p->name) && NULL != p->next)
{
q = p;
p = p->next;
}
if(0 == strcmp(x,p->name))
{
if( p == head)
head = p->next;
else
q->next = p->next;
free(p);
}
else
printf("can't find your node");
h = head;
return h;
}
//测试
Ⅳ C语言的形参struct list 和 list有什么区别吗
对于结构体类型变量定义,struct
list和list在C++中是相同的,都是正确的。
但在C语言中,如果没有经过重定义处理,则会编译报错。如:
typedef struct list
{
int data;
struct list *next;
} list ;这样之后,可以使用struct
list
或
list
来定义变量了,如:
struct
list
*
link
;
list
*
link1
;
Ⅵ c语言中的struct list是什么意思,它代表什么东西。怎么使用
struct
friends_list
f;
就是定义简单的结构体变量f
friends[count]
=
f;
就是把结构体变量f赋值给结构体数组friends的第count个元素
Ⅶ C语言中的--)是代表什么 j--)L->list[j]=L->list[j-1] 是什
j--; 是 j 后缀自减1;在表达式里 用 j 的当前值,出表达式后 自减 1,即 j=j-1.
L 是结构指针。
list 是L指向的结构 的 成员数组名字,
list[j] 是数组list的一个元素,下标 j
list[j-1] 是数组list的一个元素,下标 j -1
L->list[j] = L->list[j-1]; 是赋值语句,把 结构成员数组里的 j-1 元素的值 赋给 j 元素。
Ⅷ c语言中,int i,j,list(10),这里的list(10)代表什么意思
在C++中才可以写list(10),并且list的值被初始化为10.但是有一个问题:list是一个容器类型,你这样写应该会有问题。就像vector一样。
Ⅸ 如何用C语言或C++实现一个List类
C语言没有类的概念。C++有现成的List类, #include<list>即可。
如果要自己实现可以参考C++数据结构的书籍,是最基本的练习。
这里实现一个简单的例程,请参考:
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<string.h>
usingnamespacestd;
#include<stdio.h>
#include<string>
#include"math.h"
template<classT>classList{
public:
List()//构造函数
{
pFirst=NULL;
}
voidAdd(T&t)//在Link表头添加新结点
{
if(pFirst==NULL)
{
pFirst=newNode;
*(pFirst->pT)=t;
}
else
{
Node*pNewNode=newNode;
*(pNewNode->pT)=t;
pNewNode->pNext=pFirst;
pFirst=pNewNode;
}
}
voidRemove(T&t)//在Link中删除含有特定值的元素
{
Node*pNode=pFirst;
if(*(pNode->pT)==t)
{
pFirst=pFirst->pNext;
deletepNode;
return;
}
while(pNode!=NULL)
{
Node*pNextNode=pNode->pNext;
if(pNextNode!=NULL)
{
if(*(pNextNode->pT)==t)
{
pNode->pNext=pNextNode->pNext;
deletepNextNode;
return;
}
}
else
return;//没有相同的
pNode=pNode->pNext;
}
}
T*Find(T&t)//查找含有特定值的结点
{
Node*pNode=pFirst;
while(pNode!=NULL)
{
if(*(pNode->pT)==t)
{
returnpNode->pT;
}
pNode=pNode->pNext;
}
returnNULL;
}
voidPrintList()//打印输出整个链表
{
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;
deletepNode;
pNode=pNextNode;
}
}
protected:
structNode{
Node*pNext;
T*pT;
Node()
{
pNext=NULL;
pT=newT;
}
~Node()
{
deletepT;
}
};
Node*pFirst;//链首结点指针
};
classStudent
{
public:
charid[20];//学号
charname[20];//姓名
intage;//年龄
Student()
{
}
~Student()
{
}
Student(constchar*pid,constchar*pname,int_age)
{
strcpy(id,pid);
strcpy(name,pname);
age=_age;
}
booloperator==(constStudent&stu)
{
returnstrcmp(id,stu.id)==0&&strcmp(id,stu.id)==0&&age==stu.age;
}
Student&operator=(constStudent&stu)
{
strcpy(id,stu.id);
strcpy(name,stu.name);
age=stu.age;
}
friendostream&operator<<(ostream&out,constStudent&stu);
};
ostream&operator<<(ostream&out,constStudent&stu)
{
out<<"id:"<<stu.id<<" name:"<<stu.name<<" age:"<<stu.age<<endl;
}
intmain()
{
List<Student>stuList;
cout<<"添加学生前:"<<endl;
stuList.PrintList();
Studentstu1("1","张三",18);
Studentstu2("2","李四",18);
Studentstu3("3","王五",18);
Studentstu4("4","至尊宝",18);
Studentstu5("5","猪八戒",18);
Studentstu6("6","唐僧",18);
Studentstu7("7","沙和尚",18);
Studentstu8("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();
Studentstu11("1","张三",18);
Student*pStu=stuList.Find(stu11);
cout<<"查找到的同学是:"<<*pStu;
stuList.Remove(stu11);
cout<<" 删除第一个后:"<<endl;
stuList.PrintList();
return0;
}
Ⅹ C语言中的list是指什么求一个简单的list代码
C语言中没有list
list是C++中的一个类
具体使用可以从网上查一下,有很多应用
