#include
using namespace std;
typedef struct SLnode
{
int data;
struct SLnode* next;
}SLnode;
void crealist(SLnode &head,int a[],int n)
{
head=(SLnode)malloc(sizeof(SLnode));
SLnode *p=head;
SLnode x;
for(int i =0;i<n;i++)
{
x=(SLnode)malloc(sizeof(SLnode));
x->data=a[i];
x->next=NULL;
p->next=x;
p=x;
}
}
void delmin(SLnode *&head)
{
SLnode *minp,*p,*minpre,*pre;
p=head->next;
minp=p;
minpre=head;
pre=head;
while(p!=NULL)
{
if(p->datadata)
{
minpre=pre;
minp=p;
}
pre=p;
p=p->next;
}
minpre->next=minp->next;
free(minp);
}
int main()
{
int a[]={0,1,5,4,7};
int o =5;
SLnode *p;
crealist(p,a,o);
delmin§;
SLnode *x=p->next;
while(x!=NULL)
{
std::cout << x->data << std::endl;
x=x->next;
}
}
本文介绍了一个使用C++实现的单链表的基本操作,包括如何根据给定的一组整数创建单链表,并从该链表中删除具有最小值的节点。通过具体的代码示例展示了创建链表的过程及寻找并移除最小值节点的方法。
1100

被折叠的 条评论
为什么被折叠?



