链表笔记之1
?
#include <stdlib.h>/*標(biāo)準庫函數(shù)*/
#include <stdio.h>/*I/O函數(shù)*/
#include <string.h>/*字符串函數(shù)*/
#include <ctype.h>/*字符操作函數(shù)*/
#include "linkedlist.h"
#include "hashtable.h"
#include "queue.h"
typedef struct student
{
??? int id;
??? char name[15];
} student; //節(jié)點定義
//鏈表的遍歷
void print_linked_list(LinkedList* list)
{
??? if(list->head == NULL)
??? {
??????? printf("print_link函數(shù)執(zhí)行,鏈表為空\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");
}
//鏈表的結(jié)點刪除
void delete_linked_list_node(LinkedList* list,int no)
{
??? if(list->head == NULL)
??? {
??????? printf("print_link函數(shù)執(zhí)行,鏈表為空\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;
}
?
總結(jié)
 
                            
                        - 上一篇: VS2008 JS调试和Silverli
- 下一篇: 梦到蛇和牛打架是什么意思
