473,406 Members | 2,439 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,406 software developers and data experts.

resolving a linked-list of numbers to a range

Thanks everyone i got it to work at last but how would we resolve
numbers inside a integer linked-list and ive been writing out
flow-chart for this problem but i cant seem to be getting my head
around it

here is a code that i wanted

typedef struct intnode
{
int data;
struct intnode *next;

}IntNode;

typedef struct listhead
{
IntNode *head;
int count;

}ListHead

.....

void printList(ListHead * lh)
{
IntNode *current = lh->head;
int prevNum =0, x=0;
while (current != NULL)
{
if (prevNum > 0)
{
if( (prevNum+1) == current->data)
{
if(x==0)
{
printf("-");
x=1;
}
}
else if( (prevNum+1) != current->data)
{
printf("%s,%s",prevnum,current->data);
x=0; /* To display '-' for next series of numbers */
}
}
}
prevNum = current->data;
current = current->next;
}

}

the problem i think was i was thinking of a solution to this problem if
arrays where used now that i want to change it to LL structure im
confused, so any help will be appreciated again

Nov 15 '05 #1
6 1593
AM

placid wrote:
Thanks everyone i got it to work at last but how would we resolve
numbers inside a integer linked-list and ive been writing out
flow-chart for this problem but i cant seem to be getting my head
around it

here is a code that i wanted

typedef struct intnode
{
int data;
struct intnode *next;

}IntNode;

typedef struct listhead
{
IntNode *head;
int count;

}ListHead

....


If I understand your problem correctly then following data-structure
implementation may be more efficient.

typedef struct intnode
{
int start;
int count;
IntNode *next;
} IntNode;

So, for the input:
1 2 3 4 5 7 8 9 13

Link list nodes would be:
{1, 5} --> {7, 3} --> {13, 0} --> NULL

Thanks
-AM

Nov 15 '05 #2
No, if the input is 1 2 4 5 21 30
{1} -> {3} -> {4} -> {5} -> {21}->{30}->NULL

my question is when i print it out i want it in a range so something
like

1-5,21,30

Nov 15 '05 #3
In article <11*********************@g47g2000cwa.googlegroups. com>,
placid <Bu****@gmail.com> wrote:
Thanks everyone i got it to work at last but how would we resolve
numbers inside a integer linked-list and ive been writing out
flow-chart for this problem but i cant seem to be getting my head
around it while (current != NULL)
{
if (prevNum > 0)
{
if( (prevNum+1) == current->data)
{
if(x==0)
{
printf("-");
x=1;
}
}
else if( (prevNum+1) != current->data)
That test is redundant unless you are working with double precision
where values might be "NaN" (Not A Number), in which case IEEE 754
specifies that a NaN does not compare equal to itself. But other than
that case, this if is just the negation of the previous if and so
is automatically true if you get there at all, because of the 'else'.
printf("%s,%s",prevnum,current->data);


prevnum and current->data are integers, but %s is a format
specifier that expects a pointer to a null-terminated character array.
Try %d instead of %s .
Your logic is kind of strange, but strange algorithms are the
province of comp.programming not of comp.lang.c, which tries
to restrict itself to discussion of language features.

--
Ceci, ce n'est pas une idée.
Nov 15 '05 #4
wait now i didnt see that befor i thought i was using %d

Nov 15 '05 #5
placid wrote:

No, if the input is 1 2 4 5 21 30
{1} -> {3} -> {4} -> {5} -> {21}->{30}->NULL

my question is when i print it out i want it in a range so
something like

1-5,21,30


What, if anything, are you talking about? Include proper context.
Each usenet article should stand by itself. Even on google you can
do it, see below:

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 15 '05 #6

CBFalconer wrote:
placid wrote:

No, if the input is 1 2 4 5 21 30
{1} -> {3} -> {4} -> {5} -> {21}->{30}->NULL

my question is when i print it out i want it in a range so
something like

1-5,21,30


What, if anything, are you talking about? Include proper context.
Each usenet article should stand by itself. Even on google you can
do it, see below:

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


thanks for the tip

Nov 15 '05 #7

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

Similar topics

0
by: Olav | last post by:
Resolving character references with C++/Arabica I have an element that looks like this: <PhoneNumber>&lt;NUMBER&gt;</PhoneNumber> I would like to have the content returned as "<NUMBER>". Not...
1
by: Vineeth | last post by:
Hi, I am using xerces2.6.0 and am developing a program for converting an xml document to a text file. My program is extending the DefaultHandler. The first problem I am facing is that even...
2
by: Gustaf Liljegren | last post by:
I need to merge several XML files into one large. All of them has a DOCTYPE tag, but the SYSTEM identifier points to a DTD that doesn't exist. (I use the PUBLIC identifier with catalog files, so...
0
by: Wanderer | last post by:
Hi all, who knows how to correctly make assembly resolving in asp.net? In WinApplications AppDomain.CurrentDomain.AssemblyResolve event works fine, but this is not a case of asp.net. If I...
1
by: Steve W | last post by:
I hope this makes sense ! We have an VB ASP.NET Web Application. In the bin directory are all our compiled dlls. We have written some integration with a 3rd party, which some of our clients...
1
by: Stephen | last post by:
Hi all, is there a way that I can create an application that can "Resolve" any given address in the URL to be redirected to a default website. I guess that It can be done by "Resolving DNS...
1
by: Ghislain Tanguay | last post by:
Hi everyone, this is the code I use now for resolving domain address with email. But I use an external program "nslookup" to verify my addresses. Is there an intrinsic object in dotnet who do...
4
by: RJDev | last post by:
Hi, Is there anyone who can help me in resolving the Application Name of my IIS Aaplication. I want to check the application name to see what configuration i need to use because multiple virtual...
7
by: Trac Bannon | last post by:
When I load XML from a file into a dotNet XMLDataDocument, the UTF-8 codes are resolved but the 5 special XML entities are not. How can I force those 5 special character types to be translated?
2
by: John Kotuby | last post by:
Hi all, I have been working on transferring my development environments to a new Vista ultimate machine (from XP) and am running into difficulties. After patching both SQL Server 2005 and VS 2005,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.