irving-l / algorithm_frombilibili Goto Github PK
View Code? Open in Web Editor NEW《B站-青岛大学-王卓老师-数据结构与算法基础》自学心得、笔记(C++语言实现)
《B站-青岛大学-王卓老师-数据结构与算法基础》自学心得、笔记(C++语言实现)
void CreatListTail(LinkList &L, const size_t n)
{
Lnode *r = L;
for (int i = 0; i < n; ++i)
{
Lnode *p = new Lnode;
cin >> p->data;
p->next = NULL; #这里是不是应该改成NULL,原来写的是r->next
r->next = p;
r = r->next;
}
}
大佬,串和广义表的算法代码还有吗
树那里前8段代码就错了3、4个 你自己都没运行成功发出来干嘛呢 好看?感动自己?
二叉树先序遍历函数的传入参数为什么要加“&”?
void InsertBSTree(BSTree &T, const ElemType &e)
// 原代码
if (T == nullptr)
{
T = new BSNode;
T->data = e;
}
// 此处的树左右孩子应置为空指针,更改后的代码
if (!T)
{
T = new BSTNode;
T->data = e;
T->lchild = nullptr;
T->rchild = nullptr;
}
void CreatBSTree(BSTree &T)
// 原代码
while(cin>>input.key)
{
vec.push_back(input);
}
// 此处应加入输入终止条件(如回车键终止输入),更改后的代码
while (cin >> input.key)
{
vec.push_back(input);
if(cin.get() == '\n')
{
break;
}
}
图这一章的结构体的邻接矩阵应该是二维的,不然下面的G.arcs[i][j]怎么赋值?
个人愚见int Arcs[MAXSIZE][MAXSIZE];
在创建无向网时,第一个cin有问题,重复输入值在同一个中。
个人愚见cin>>G.vexnum>>G.arcnum;
大佬,单向链表的销毁链表是不是有问题啊
int main()
{
int N = 10;
Lnode* L;
cout << "temp" << endl;
InitList(L);
cout << L << endl;
// CreateListHead(L, 3);
CreateListTail(L, 3);
cout << L->next->data << endl;
// cout << L->next + 1<< endl;
// cout << L->next->data<< endl;
cout << IsEmpty(L) << endl;
DestroyList(L);
cout << IsEmpty(L) << endl;
return 0;
}
执行的时候,到 DestroyList(L); 的时候直接core dump退出了
你没有考虑链表为空的情况,如果L->next为NULL,则无法执行p->next = L->next。
正确的应该这样
void CreatListHead(LinkList &L, const int n)
{
for (int i = 0; i < n; ++i)
{
DuLnode *p = new DuLnode;
if (p == NULL)
{
cout << "Memory allocation failed." << endl;
return;
}
p->note.name = rand_str(5);
// cin >> "input name:">>p->note.name;
p->note.age = rand() % 100;
// cin >> "input age:">>p->note.age;
p->prior = L;
if (L->next == NULL)
{ // the list is empty
p->next = NULL;
}
else
{ // the list is not empty
p->next = L->next;
L->next->prior = p;
}
L->next = p;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.