链表的插入排序
下面的程序是實現了鏈表的插入排序:
#include<iostream> using namespace std; typedef struct LNode{int data;struct LNode *next; }; int main(){LNode *head=new LNode;head->data=NULL;head->next=NULL;LNode *p;int n;while(cin>>n){LNode *q=new LNode;q->data=n;q->next=NULL;p=head;while(p->next!=NULL&&p->next->data<q->data)p=p->next;if(p->next==NULL)p->next=q;else{q->next=p->next;p->next=q;}}p=head->next;while(p!=NULL){cout<<p->data<<" ";p=p->next;}cout<<endl;delete head;delete p;return 0; }轉載于:https://blog.51cto.com/beyond316/1256053
總結
- 上一篇: ods文件怎么打开?ods是什么意思?(
- 下一篇: js实现选中文字 分享功能