C語言資料結構之順序表和單鏈表

2022-09-25 01:15:12 字數 2390 閱讀 3845

#define _crt_secure_no_warnings 1

#include

struct sqlist ;

void initlist(sqlist& l)

l.length = 0;

}void charu(sqlist& l)

}void listinsert(sqlist& l, int i, int e)

l.date[i - 1] = e;

l.length++;

}void print(sqlist& l)

printf("\n");

}void listdelete(sqlist& l, int i, int e)

l.length--;

}int main()

以上操作分別實現了對順序表的建立,插入,刪除和列印

#define _crt_secure_no_warnings 1

#include

#include

struct listnode ;

struct listnode* create(struct listnode* head)

else

p2 = p1;

p1= (struct listnode*)malloc(sizeof(struct listnode));

scanf("%d", &p1->num);

}p2->next = null;

free(p1);

return head;

}void print(struct listnode* head)

}int main()

以上操作為建立鍊錶並列印,效果如下:

現在增加插入操作

#define _crt_secure_no_warnings 1

#include

#include

struct listnode ;

struct listnode* create(struct listnode* head)

else

p2 = p1;

p1= (struct listnode*)malloc(sizeof(struct listnode));

scanf("%d", &p1->num);

}p2->next = null;

free(p1);

return head;

}void print(struct listnode* head)

printf("\n");

}struct listnode* insert(struct listnode* head,int i)

p= (struct listnode*)malloc(sizeof(struct listnode));

printf("請輸入插入的數:");

scanf("%d", &p->num);

p2->next = p;

p->next = p1;

return head;

}int main()

效果如下:

現增加刪除操作

#define _crt_secure_no_warnings 1

#include

#include

struct listnode ;

struct listnode* create(struct listnode* head)

else

p2 = p1;

p1= (struct listnode*)malloc(sizeof(struct listnode));

scanf("%d", &p1->num);

}p2->next = null;

free(p1);

return head;

}void print(struct listnode* head)

printf("\n");

}struct listnode* insert(struct listnode* head,int i)

p= (struct listnode*)malloc(sizeof(struct listnode));

printf("請輸入插入的數:");

scanf("%d", &p->num);

p2->next = p;

p->next = p1;

return head;

}struct listnode* delete(struct listnode* head, int i)

if (p1 == head)

else

return head;

}int main()

效果如下:

因此,我們便實現了對單鏈表的建立、刪除、增加和輸出

資料結構 順序表和單鏈表c

include using namespace std constexpr auto maxsize 100 constexpr auto error 0 constexpr auto ok 1 typedef int elemtype 順序表的儲存結構 typedef struct sqlist ...

資料結構 順序表和單鏈表

typedef struct sqlist sqlist,psqlist bool isfull psqlist psq bool isempty psqlist psq void initsqlist psqlist psq 初始化 bool insert psqlist psq,int pos,...

c語言資料結構之單鏈表

本教程會在以後持續公布c語言資料結構的實現文章,一來重溫一下基礎知識,二來為正在學習此部分內容的同學提供參考和思路,教程內容均來自於書籍 分享和本人思考,側重 編寫和實現,詳細的理論論述還是要翻閱經典的書籍,在此感謝貢獻自己智慧型的廣大程式設計人員。今天的主題是單鏈表,這是一種非常常見的資料結構,隸...