我没有在合并排序中得到输出,任何人都可以帮助我 [英] i did't get output in merge sort any one help me

查看:57
本文介绍了我没有在合并排序中得到输出,任何人都可以帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// Title:    Merge short
// Author:   Chandru K.S
// Date :    20-10-11

#include<stdio.h>
#include<conio.h>

struct node
{
int data;
struct node *next;
}*start = NULL;

int len;

void main()
{
struct node *start1;
clrscr();
insert(5);
insert(2);
insert(4);
insert(6);
insert(1);
//insert(3);
len = display();
printf("\nlist length is %d\n",len);

start1 = mergesort();
display1(start1);

getch();
}

insert(int val)
{
struct node *temp;
temp = (struct node *)malloc(sizeof(struct node));
temp->data = val;
temp->next = NULL;
if(start==NULL)
{
start = temp;
}
else
{
struct node *last = start;

while(last->next!= NULL)
last = last->next;

last->next = temp;
}
return 0;
}

display()
{
int len=0;
struct node *temp = start;
while(temp)
{
printf("%d\t",temp->data);
len=len++;
temp = temp->next;
}
return len;
}

display1(struct node *temp)
{
int len=0;
//struct node *temp = start;
while(temp)
{
printf("%d\t",temp->data);
len=len++;
temp = temp->next;
}
return len;
}
mergesort()
{
struct node *head = start;
struct node *head_one;
struct node *head_two;
struct node *head_three;

head_one = head;
head_two = head->next;
while((head_two != NULL) && (head_two->next != NULL))
{
head = head->next;
head_two = head->next->next;
}
head_two = head->next;
head->next = NULL;

//merge_sort(head_one, head_two);


//struct node *merge_sort(struct node *head_one, struct node *head_two)

if(head_one == NULL)
return head_two;

if(head_two == NULL)
return head_one;

if(head_one->data < head_two->data)
 {
head_three = head_one;
head_three->next = merge_sort(head_one->next, head_two);
}
else
{
head_three = head_two;
head_three->next = merge_sort(head_one, head_two->next);
}

//return head_three;
}

/*   merge_sort(len)
{
int i;
int j;
int k;
int q; //middle node
//int p; //starting node
//int r; // last node

struct node *first = start;
struct node *second;
struct node *l = NULL; // first list
struct node *r = NULL; // second list
struct node *temp;
temp = (struct node *)malloc(sizeof(struct node));

q = floor((len)/2);

for(i=0;i<q;i++)
{
l = inser(first);
dis(l);
for(j=q;j<len;j++)
{
r = inser(first);
dis(r);
}
}
}  */

推荐答案

阅读以下内容:
在C中合并排序 [
Read the following :
Merge sort in C[^]


这篇关于我没有在合并排序中得到输出,任何人都可以帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆