c++資料結構實驗2.1 鍊錶結構實現超級簡陋的圖書館增加刪除查詢功能。(發現自己的**真的好菜@_@)
/**2018資料結構實驗2.1 鍊錶**/
#include#include#includeusing namespace std;
//書本結構
struct book
;class library
; bool ifempty();
void add(string n, string a, string p);
void remove(string n, string a);
int find(string n);
private:
book * head;
int length;
};//是否為空
bool library::ifempty()
//增加書本
void library::add(string n, string a, string p)
//否則在原來的鍊錶上新增
else
x = x->next;
} //如果以前沒有儲存過就成功新增
if (flag == 0)
}}//刪除節點 根據name和author刪除
void library::remove(string n, string a)
if (flag == 0)
}else
}after = after->next;
x = x->next;
} //查不到需要刪除的節點
if (ifdelete != 1)
//刪除節點
else if (ifdelete == 1)
}}//根據name查詢該名字書本的數量
int library::find(string n)
else
x = x->next;
} cout << quantity << endl;
return quantity; }}
int main()
char big[7];//單次操作代號
for (j = 0; j < operations; j++)
big[k] = '\0';
//判斷big裡面的操作代號是什麼並進行操作
if (strcmp(big, "add") == 0)
nn[i] = '\0';
str2 = nn;
k = k + 2;
i = 0;
while (oper[j][k] != ')')
aa[i] = '\0';
str3 = aa;
k = k + 2;
i = 0;
while (oper[j][k] != ')')
pp[i] = '\0';
str4 = pp;
l.add(str2, str3, str4);
//cout << "name=" << str2 << endl;
} else if (strcmp(big, "remove") == 0)
nn[i] = '\0';
str2 = nn;
k = k + 2;
i = 0;
while (oper[j][k] != ')')
aa[i] = '\0';
str3 = aa;
l.remove(str2, str3);
} else if (strcmp(big, "find") == 0)
}return 0;
}
資料結構實驗一(鍊錶)
1.seqlist.h ifndef seqlist h define seqlist h const int maxsize 10 class seqlist seqlist int a,int n seqlist void insert int i,int x int delete int i ...
資料結構實驗之鍊表六 有序鍊錶的建立 C 2121
time limit 1000 ms memory limit 65536 kib problem description 輸入n個無序的整數,建立乙個有序鍊錶,鍊錶中的結點按照數值非降序排列,輸出該有序鍊錶。input 第一行輸入整數個數n 第二行輸入n個無序的整數。output 依次輸出有序鍊錶...
資料結構 鍊錶(C )
typedef int rank define listnodeposi t listnode template class listnode listnode t e,listnodeposi t p null,listnodeposi t s null data e prenode p back...