C/C++単鎖表はメニューの「増删改查」データ構造テンプレート(ファイルフロー処理なし)を含み、同時にマイクロソフトVCコンパイル時にchar配列が自動的に屯屯屯屯を追加することを解決する.
27210 ワード
C/C++シングルチェーンテーブルメニューを含む「添削・改ざん」データ構造テンプレート(ファイルフロー処理なし)
必要な学生たちを助けるために
同時に、皆さんの質問と最適化の提案を歓迎します.
char*を使用しないことでstring回転char時のVC自動充填問題を解決し、コードは以下の通りである.
必要な学生たちを助けるために
同時に、皆さんの質問と最適化の提案を歓迎します.
char*を使用しないことでstring回転char時のVC自動充填問題を解決し、コードは以下の通りである.
:
strcpy_s(Node->char[20] val, char[20] val);
:
strcpy_s(pGet->name, name); /* */
#include <iostream>
#include <assert.h>
#include <cstdlib>
using namespace std;
typedef struct Node
{
int id = 0; /* */
char name[20]; /* , name */
struct Node* next=(struct Node*)malloc(sizeof(struct Node)); /* */
}Node, * List;
void InitList(List p) /* */
{
assert(p!= NULL); /* p */
if (p->next == NULL) /* p next */
{
return;
}
p->next = NULL;
}
void Destroy(List p) /* p*/
{
Node* pDel = p->next;
while (p->next != NULL) /* p */
{
pDel = p->next;
p->next = pDel->next;
free(pDel); /* pDel*/
}
pDel = NULL;
}
static Node* GetNode(int id, char name[]) /* */
{
Node* pGet = new Node();
pGet = (Node*)malloc(sizeof(Node)); /* */
//assert(pGet == NULL); /* */
pGet->id = id;
//pGet->name = tname; /* */
//memcpy(pGet->name, name, strlen(name)); /* */
strcpy_s(pGet->name, name); /* strcpy_s name */
return pGet; /* */
}
bool Insert_head(List p, int id, char name[]) /* */
{
assert(p != NULL); /* p, */
Node* pcur = new Node();
pcur = GetNode(id, name);
pcur->next = p->next;
p->next = pcur;
return true;
}
Node* Search_pre(List p, int id) /* , */
{
Node* pcur = p;
for (; pcur->next != NULL; pcur = pcur->next)
{
if (pcur->next->id == id)
{
return pcur;
}
}
return NULL;
}
bool Delete(List p, int id) /* */
{
Node* p1 = Search_pre(p, id);
if (p1 == NULL)
{
cout << " id" << endl;
return false;
}
Node* pDel = new Node();
pDel = p1->next; /* , next*/
p1->next = pDel->next;
free(pDel);
pDel->next = NULL;
cout << " " << endl;
return true;
}
void show(List p) /* p*/
{
Node* pcur = new Node();
pcur = p->next;
while (pcur != NULL)
{
cout << pcur->id << "\t" << pcur->name << endl;
pcur = pcur->next;
}
cout << endl;
}
void welcomePanel()
{
cout << " ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
";
cout << " ┃ ┃\t
";
cout << " ┃ 1. ┃\t
";// ,
cout << " ┃ 2. ┃\t
";
cout << " ┃ 3. ┃\t
";
cout << " ┃ 4. ┃\t
";
cout << " ┃ 5. ┃\t
";
cout << " ┃ 0. ┃\t
";
cout << " ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
";
cout << " : ";
}
void operation(Node *p,int x)
{
switch (x)
{
case 1: {
InitList(p);
break;
}
case 2: {
int id;
char name[20];
cout << " ID: ";
cin >> id;
cout << " : ";
cin >> name;
cout << " : ";
cout << name;
if (Insert_head(p, id, name))
cout << " " << endl;
cout << " " << endl;
break;
}
case 3: {
Node* preNode = new Node();
int id;
cout << " ID: ";
cin >> id;
preNode = Search_pre(p, id-1);
if (preNode == NULL)
{
cout << " , ID" << endl;
}
else {
cout << " ID :" << id << " name :" << preNode->name << endl;
}
cout << " " << endl;
break;
}
case 4: {
int id;
cout << " ID: ";
cin >> id;
Delete(p, id);
cout << " ID " << endl;
break;
}
case 5: {
show(p);
cout << " " << endl;
break;
}
case 0: {
return;
}
}
int main()
{
Node* p = new Node();
InitList(p);
welcomePanel();
int x;
while ((cin >> x) && x)
{
operation(p, x);
welcomePanel();
}
}