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(ListH ead * 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 6 1615
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
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
In article <11************ *********@g47g2 000cwa.googlegr oups.com>,
placid <Bu****@gmail.c om> 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.programmin g not of comp.lang.c, which tries
to restrict itself to discussion of language features.
--
Ceci, ce n'est pas une idée.
wait now i didnt see that befor i thought i was using %d
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.c om, 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
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.c om, 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Olav |
last post by:
Resolving character references with C++/Arabica
I have an element that looks like this:
<PhoneNumber><NUMBER></PhoneNumber>
I would like to have the content returned as "<NUMBER>".
Not only don't I get the character references resolved, but also what
is only one Text-node child of the element-node becomes several nodes
|
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 though I
have turned the Validation feature off, the SAX parser still needs the
DTD to be present. If I remove the DOCTYPE declaration from the XML
file then it raises an exception for unparsed entities. If I provide a
zero byte DTD then the SX parser...
|
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 the SYSTEM identifiers has no
purpose in my application.)
Anyway, when I load each document, using XmlDocument.Load(file), I get a
FileNotFoundException, because of the DTD pointer in the SYSTEM identifier.
I'd rather skip all the entity...
|
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
use this event (I put a handler in
Global.Application_Start) it seems that either I start to
handle it too late or it doesn't come at all.
|
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 use and some that don't. Those that don't won't have a particular
dll in the bin directory of the web site.
However, removing this dll causes a problem because .Net seems to want to
| |
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 address"
Please Advice,
Stephen.
|
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 the same job?
Dim objInfoProc As New ProcessStartInfo
Dim objProc As Process
Dim objStdOut As StreamReader
Dim reg As Regex
|
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 or root Web domains are using the same app env.
Regards,
Rene
|
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?
|
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, I am now attempting to test my VB
Web Site application the same way I did in XP. IIS is running and in IIS
Management I see the default website in the correct spot, yet
http://localhost/ is not resolving. Has anyone else run into this problem...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |