當前位置:首頁 » 編程語言 » c語言中的list

c語言中的list

發布時間: 2023-01-17 17:59:42

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類

  1. C語言沒有類的概念。C++有現成的List類, #include<list>即可。

  2. 如果要自己實現可以參考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++中的一個類
具體使用可以從網上查一下,有很多應用

熱點內容
c語言期末試卷 發布:2025-07-17 05:49:58 瀏覽:404
64位access資料庫 發布:2025-07-17 05:35:58 瀏覽:374
php文件的相對路徑 發布:2025-07-17 05:34:22 瀏覽:711
矢量的叉乘運演算法則 發布:2025-07-17 05:29:41 瀏覽:661
dell雲存儲伺服器 發布:2025-07-17 05:21:06 瀏覽:255
銑床怎麼編程 發布:2025-07-17 05:20:29 瀏覽:776
sql11oracle 發布:2025-07-17 05:15:39 瀏覽:744
全國各地移動dns伺服器ip地址 發布:2025-07-17 05:07:47 瀏覽:312
sdvn加密 發布:2025-07-17 05:01:36 瀏覽:739
怎麼提取電腦緩存中的音樂 發布:2025-07-17 04:53:14 瀏覽:27