欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

list函數(shù)c語言 c語言有l(wèi)ist嗎

C語言中的list是指什么?求一個簡單的list代碼

C語言中沒有l(wèi)ist

創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站建設(shè)、網(wǎng)站制作與策劃設(shè)計,博樂網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:博樂等地區(qū)。博樂做網(wǎng)站價格咨詢:13518219792

list是C++中的一個類

具體使用可以從網(wǎng)上查一下,有很多應(yīng)用

C語言中creatlist的用法

1、createlist不是庫函數(shù),一般是數(shù)據(jù)結(jié)構(gòu)中實(shí)現(xiàn)新建一個鏈表的自定義函數(shù)。因此沒有什么用法好說的,關(guān)鍵是看自己怎么定義。

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語言函數(shù)insert_list完成將給定的數(shù)據(jù)插入到單鏈表的指定位置上

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++實(shí)現(xiàn)一個List類?

C語言沒有類的概念。C++有現(xiàn)成的List類, #includelist即可。

如果要自己實(shí)現(xiàn)可以參考C++數(shù)據(jù)結(jié)構(gòu)的書籍,是最基本的練習(xí)。

這里實(shí)現(xiàn)一個簡單的例程,請參考:

#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()??//構(gòu)造函數(shù)

{

pFirst?=?NULL;

}

void?Add(T?t)??//在Link表頭添加新結(jié)點(diǎn)

{

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)??//查找含有特定值的結(jié)點(diǎn)

{

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;????????//鏈?zhǔn)捉Y(jié)點(diǎn)指針

};

class?Student

{

public:

char?id[20];????//學(xué)號

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"添加學(xué)生前:"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"添加學(xué)生后:"endl;

stuList.PrintList();

Student?stu11("1",?"張三",?18);

Student*?pStu?=?stuList.Find(stu11);

cout"查找到的同學(xué)是:"*pStu;

stuList.Remove(stu11);

cout"\n\n刪除第一個后:"endl;

stuList.PrintList();

return?0;

}

當(dāng)前標(biāo)題:list函數(shù)c語言 c語言有l(wèi)ist嗎
分享鏈接:http://chinadenli.net/article22/dodigjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、品牌網(wǎng)站建設(shè)網(wǎng)站改版、虛擬主機(jī)、App設(shè)計、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)