日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

链表笔记之1

發布時間:2023/11/29 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 链表笔记之1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

#include <stdlib.h>/*標準庫函數*/
#include <stdio.h>/*I/O函數*/
#include <string.h>/*字符串函數*/
#include <ctype.h>/*字符操作函數*/
#include "linkedlist.h"
#include "hashtable.h"
#include "queue.h"


typedef struct student
{
??? int id;
??? char name[15];
} student; //節點定義

//鏈表的遍歷
void print_linked_list(LinkedList* list)
{
??? if(list->head == NULL)
??? {
??????? printf("print_link函數執行,鏈表為空\n");
??????? return;
??? }
??? while(list->head!=NULL)
??? {
??????? student* st=(student*)list->head->data;
??????? printf("%d %s\n",st->id,st->name);
??????? list->head=list->head->next;
??? }
??? printf("\n");
}

//鏈表的結點刪除
void delete_linked_list_node(LinkedList* list,int no)
{
??? if(list->head == NULL)
??? {
??????? printf("print_link函數執行,鏈表為空\n");
??????? return;
??? }

??? LinkedListNode *node = NULL, *tmp = NULL;
??? node=tmp=list->head;

??? int id=((student*)node->data)->id;
??? if(id==no)
??? {
??????? list->head=node->next;
??????? free(node);
??? }
??? else
??? {
??????? while((id!=no)&&(node->next!=NULL))
??????? {
??????????? id=((student*)node->data)->id;
??????????? tmp = node;
??????????? node = node->next;
??????? }
??????? if(id==no)
??????? {
??????????? tmp->next=node->next;
??????????? free(node);
??????? }
??? }
}

int main(int argc, char *argv[])
{
??? /*
??? LinkedList *list = NULL;
??? list=linked_list_construct();
??? int i=0;
??? while(i<5)
??? {
??? ?LinkedListNode *node=NULL;
??? ?node=(LinkedListNode *)malloc(sizeof(LinkedListNode));
??? ?memset(node,0,sizeof(LinkedListNode));

??? ?student* st=NULL;
??? ?st=(student *)malloc(sizeof(student));
??? ?memset(st,0,sizeof(student));

??? ?st->id=i;
??? ?sprintf(st->name,"%s%d","方欣_",i);
??? ?node->data=st;
??? ?linked_list_append_node(list,node);
??? ?i++;
??? }

??? //linked_list_remove_node(list,node);
??? //linked_list_destroy(list);
??? //int ret=linked_list_is_empty(list);
??? //printf("%s\n",ret==1?"鏈表為空":"鏈表非空");
??? delete_linked_list_node(list,2);
??? print_linked_list(list);*/


??? /*
??? ?HashTable* ht=NULL;
??????? ht=hash_table_construct(5);
??????? int j=0;
??? ?while(j<5)
??? ?{
??? ??student* st=NULL;
??? ??st=(student *)malloc(sizeof(student));
??? ??memset(st,0,sizeof(student));
??? ??st->id=j;
??? ??sprintf(st->name,"%s%d","方欣_",j);
??? ??hash_table_add_element(ht,st,j);
??? ??j++;
??? ?}

??? ?int k;
??? ?for(k=0;k<5;++k)
??? ?{
??? ??student* st=NULL;
??????? ?st=(student*)hash_table_get_element(ht,k);
??? ??printf("%d %s\n",st->id,st->name);
??? ?}*/

??? /*
??? ?hash_table_remove_element(ht,2);
??? ?student* stu=NULL;
??????? stu=(student*)hash_table_get_element(ht,3);
??????? if(stu!=NULL)
??????? {
??????? ?printf("%d %s\n",stu->id,stu->name);
??????? }*/


??? //int index=hash_table_get_index(ht,4);
??? //printf("%d\n",index);

??? //char* code="E:\\fxd\\hd_mw\\src\\dg_ip_program";
//??? int index=hash_table_get_hash_code_from_string(code);
//??? printf("%d\n",index);

??? //hash_table_destroy(ht);

??? Queue * qu=queue_construct();//初始化隊列
??? int j=0;
??? while(j<5)
??? {
??????? student* st=NULL;
??????? st=(student *)malloc(sizeof(student));
??????? memset(st,0,sizeof(student));
??????? st->id=j;
??????? sprintf(st->name,"%s%d","方欣_",j);
??????? queue_enqueue(qu,st);//入隊
??????? j++;
??? }
??? int ret;
??? ret=queue_length(qu);
??? printf("%d\n",ret);

??? /*
??? ?queue_destroy(qu);//銷毀隊列
??? ?ret=queue_is_empty(qu);
??? ?printf("%s\n",ret==1?"隊列為空":"隊列非空"); */
??? /*
??? int k;
??? for(k=0;k<5;++k)
??? {
??? ?student* st=NULL;
??? ?st=(student *)malloc(sizeof(student));
??? ?memset(st,0,sizeof(student));
??? ?st=(student *)queue_dequeue(qu);//出隊
??? ?printf("%d %s\n",st->id,st->name);
??? }*/
??? return 0;
}

?

總結

以上是生活随笔為你收集整理的链表笔记之1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。