文章

2

粉丝

362

获赞

1

访问

15.8k

头像
带头链表的创建和排序
P1015 贵州大学机试题
发布于2020年5月27日 18:06
阅读数 8.2k

#include<bits/stdc++.h>
using namespace std;

struct node{
    int element;
    node* next;
};
//创建链表 
node* create(int array[]){
    node *p, *pre,*head;
    head = new node();
    head->element = NULL;
    pre = head;
    for(int i =0;i<5;i++){
        p = new node();
        p->element = array[i];
        p->next = NULL;
        pre->next = p;
        pre = p;
    }
    return head;//返回头结点 
}
//排序
void sort(node* head){
    node *tail,*p,*t;//rail为末端元素,p为值最小元素,t为最小值的前一个元素 
    tail = head->next;
    while(tail->next != NULL){
        tail = tail->next;//移到...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发