473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Error of List Sorting

Hi Everybody,
This is i am trying for sorting linked using pointer..........
but i dont know wthere this logic is good or not...........
please correct eroor.......it is not working ,i t simple looping
thats it
please correct this error
By
CNS
---------------------->

#include<stdio.h>
#include<stdlib.h>
int main(void)
{
struct list
{
int a;
struct list *next;
};
struct list *head ,*curr, *top,
*a1=NULL,*a2=NULL,*temp,*a1parent=NULL,*a2parent=N ULL;
head=NULL;
int i;
int value;
for(i=0;i<=10;i++)
{
curr=(struct list *)malloc(sizeof(struct list *));
curr->a=rand()%100;
curr->next =NULL;
if (head==NULL)
{
head=curr;
}
else
{
top->next =curr;
}
top=curr;
}
a1parent=head;
for(a1=head;a1;a1=a1->next)
{
a2parent=head;
for(a2=head;a2->next!=NULL;a2=a2->next)
{
if(a1->a < a2->a)
{
/* value=a1->a;
a1->a=a2->a;
a2->a=value;*/
if (a1->next ==NULL)
{
printf("\na1 next null");
scanf("%d",i);
a1parent->next=a2;
temp=a2->next;
a2->next=NULL;
a1->next=temp;
a2parent->next=a1;
printf("\na1 next null end");
}
else if (a2->next ==NULL)
{
printf("\na2 next null");
a2parent->next=a1;
temp=a1->next;
a1->next=NULL;
a2->next=temp;
a1parent->next=a2;
printf("\na2 next null end");
}
else if(a1==head && a2->next==NULL)
{
a2->next=a1->next;
head=a2;
a2parent->next=a1;
a1->next=NULL;
}
else if (a2==head && a2->next==NULL)
{
a2->next=a2->next;
head=a1;
a1parent->next=a2;
a2->next=NULL;
}
else if(a1==head)
{
printf("\na1 head ");
scanf("%d",&i);
temp=a2->next;
a2->next=a1->next;
head=a2;
a2parent->next=a1;
a1->next=temp;
printf("\na1 head END ");

}
else if (a2==head)
{
printf("\na2 head ");
scanf("%d",&i);
temp=a1->next;
a1->next=a2->next;
head=a1;
a1parent->next=a2;
a2->next=temp;
printf("\na2 head end");

}

else
{
temp=a2->next;
a1parent->next=a2;
a2->next=a1->next;
a2parent->next=a1;
a1->next=temp;
}
}
a2parent=a2;
}

a1parent=a1;
printf("for 1 ok");
}
for (top = head; top; top = top->next)
printf("%d\n", top->a);
free(head);
}

Nov 15 '05 #1
4 1401

chellappa wrote:
Hi Everybody,
This is i am trying for sorting linked using pointer..........
but i dont know wthere this logic is good or not...........
please correct eroor.......it is not working ,i t simple looping
thats it
please correct this error
By
CNS
---------------------->

#include<stdio.h>
#include<stdlib.h>
int main(void)
{
struct list
{
int a;
struct list *next;
};
struct list *head ,*curr, *top,
*a1=NULL,*a2=NULL,*temp,*a1parent=NULL,*a2parent=N ULL;
head=NULL;
int i;
int value;
for(i=0;i<=10;i++)
{
curr=(struct list *)malloc(sizeof(struct list *));
curr->a=rand()%100;
curr->next =NULL;
if (head==NULL)
{
head=curr;
}
else
{
top->next =curr;
}
top=curr;
}
a1parent=head;
for(a1=head;a1;a1=a1->next)
{
a2parent=head;
for(a2=head;a2->next!=NULL;a2=a2->next)
{
if(a1->a < a2->a)
{
/* value=a1->a;
a1->a=a2->a;
a2->a=value;*/
if (a1->next ==NULL)
{
printf("\na1 next null");
scanf("%d",i);
a1parent->next=a2;
temp=a2->next;
a2->next=NULL;
a1->next=temp;
a2parent->next=a1;
printf("\na1 next null end");
}
else if (a2->next ==NULL)
{
printf("\na2 next null");
a2parent->next=a1;
temp=a1->next;
a1->next=NULL;
a2->next=temp;
a1parent->next=a2;
printf("\na2 next null end");
}
else if(a1==head && a2->next==NULL)
{
a2->next=a1->next;
head=a2;
a2parent->next=a1;
a1->next=NULL;
}
else if (a2==head && a2->next==NULL)
{
a2->next=a2->next;
head=a1;
a1parent->next=a2;
a2->next=NULL;
}
else if(a1==head)
{
printf("\na1 head ");
scanf("%d",&i);
temp=a2->next;
a2->next=a1->next;
head=a2;
a2parent->next=a1;
a1->next=temp;
printf("\na1 head END ");

}
else if (a2==head)
{
printf("\na2 head ");
scanf("%d",&i);
temp=a1->next;
a1->next=a2->next;
head=a1;
a1parent->next=a2;
a2->next=temp;
printf("\na2 head end");

}

else
{
temp=a2->next;
a1parent->next=a2;
a2->next=a1->next;
a2parent->next=a1;
a1->next=temp;
}
}
a2parent=a2;
}

a1parent=a1;
printf("for 1 ok");
}
for (top = head; top; top = top->next)
printf("%d\n", top->a);
free(head);
}

It's hard to see your codes.Dizzy...

Nov 15 '05 #2
I agree...

Suggestions for future posts:
Use correct grammar.
Use correct spelling.
Attempt to compress your code as much as possible.
Don't use 8-space tabs.

As for your logic, compare what you've done to any decent C book. It's
recommended you don't deviate from the method shown there.

Nov 15 '05 #3

chellappa wrote:
Hi Everybody,
This is i am trying for sorting linked using pointer..........
but i dont know wthere this logic is good or not...........
please correct eroor.......it is not working ,i t simple looping
thats it
please correct this error
By
CNS
---------------------->

#include<stdio.h>
#include<stdlib.h>
int main(void)
{
struct list
{
int a;
struct list *next;
};
struct list *head ,*curr, *top,
*a1=NULL,*a2=NULL,*temp,*a1parent=NULL,*a2parent=N ULL;
head=NULL;
int i;
int value;
for(i=0;i<=10;i++)
{
curr=(struct list *)malloc(sizeof(struct list *));
curr->a=rand()%100;
curr->next =NULL;
if (head==NULL)
{
head=curr;
}
else
{
top->next =curr;
}
top=curr;
}
a1parent=head;
for(a1=head;a1;a1=a1->next)
{
a2parent=head;
for(a2=head;a2->next!=NULL;a2=a2->next)
{
if(a1->a < a2->a)
{
/* value=a1->a;
a1->a=a2->a;
a2->a=value;*/
if (a1->next ==NULL)
{
printf("\na1 next null");
scanf("%d",i);
a1parent->next=a2;
temp=a2->next;
a2->next=NULL;
a1->next=temp;
a2parent->next=a1;
printf("\na1 next null end");
}
else if (a2->next ==NULL)
{
printf("\na2 next null");
a2parent->next=a1;
temp=a1->next;
a1->next=NULL;
a2->next=temp;
a1parent->next=a2;
printf("\na2 next null end");
}
else if(a1==head && a2->next==NULL)
{
a2->next=a1->next;
head=a2;
a2parent->next=a1;
a1->next=NULL;
}
else if (a2==head && a2->next==NULL)
{
a2->next=a2->next;
head=a1;
a1parent->next=a2;
a2->next=NULL;
}
else if(a1==head)
{
printf("\na1 head ");
scanf("%d",&i);
temp=a2->next;
a2->next=a1->next;
head=a2;
a2parent->next=a1;
a1->next=temp;
printf("\na1 head END ");

}
else if (a2==head)
{
printf("\na2 head ");
scanf("%d",&i);
temp=a1->next;
a1->next=a2->next;
head=a1;
a1parent->next=a2;
a2->next=temp;
printf("\na2 head end");

}

else
{
temp=a2->next;
a1parent->next=a2;
a2->next=a1->next;
a2parent->next=a1;
a1->next=temp;
}
}
a2parent=a2;
}

a1parent=a1;
printf("for 1 ok");
}
for (top = head; top; top = top->next)
printf("%d\n", top->a);
free(head);
}


I agree...

Suggestions for future posts:
Use correct grammar.
Use correct spelling.
Attempt to compress your code as much as possible.
Don't use 8-space tabs.

As for your logic, compare what you've done to any decent C book. It's
recommended you don't deviate from the method shown there.

Nov 15 '05 #4
jo*********@gmail.com writes:
I agree...
You agree with what? Don't assume that readers can easily see the
article to which you're replying; provide some context. Search this
newsgroup for "context, dammit" for numerous explanations.
Suggestions for future posts:
Use correct grammar.
Yes.
Use correct spelling.
Yes.
Attempt to compress your code as much as possible.
Depends on what you mean by "compress". Trimming out whatever isn't
necessary to make the point (while keeping the program complete and
compilable) is good. Compressing the code by, for example,
eliminating all whitespace is bad.
Don't use 8-space tabs.


Don't use tabs at all in code posted to Usenet. A reasonable
indentation level is 4 spaces.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tim Pascoe | last post by:
I'm trying to implement a sorting routine for a string array. The sort routine is from http://ourworld.compuserve.com/homepages/attac-cg/acgsoft.htm (a great selection of routines in the 'Sequence...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
2
by: awiklund | last post by:
Hi, I am sorting an arrayList using a custom comparer, but it sort the element in a uncommon fashion. Take a look at this code. using System; namespace ConsoleApplication8
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
44
by: Josh Mcfarlane | last post by:
Just out of curiosity: When would using std::list be more efficient / effective than using other containers such as vector, deque, etc? As far as I'm aware, list doesn't appear to be...
6
by: miky | last post by:
Hi, I'm trying to get custom gridview paging working and I'm getting the following error: "ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'count' that has parameters:...
10
by: Dustan | last post by:
I'm hiding some of the details here, because I don't want to say what I'm actually doing. I have a special-purpose class with a __cmp__ method all set up and ready to go for sorting. Then I have...
16
by: Michael M. | last post by:
How to find the longst element list of lists? I think, there should be an easier way then this: s1 = s2 = s3 = if len(s1) >= len(s2) and len(s1) >= len(s3): sx1=s1 ## s1 ist längster
4
by: rajtalent | last post by:
hi all, I want to sort the colum when clicks the columnheader using vb.net 2005 .But i receive the following error "Error 1 Overload resolution failed because no accessible 'New' accepts...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.