473,657 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sorting a doubly linked list/node

Alright, I must say that the problem my teacher has given us to do has
royally annoyed me.
We are to take a letter *txt file* and then read in the words.

Make 2 seperate lists *even and odd* for the number of occurances...

so the first time a word is entered its going to have an occurance of
one and be in the odd list then it is going to go to the next word see
if its in the odd list. If its not its going to check the even list. if
its in the even list it will add one to the occurance move it to the
odd list and then take it out of the evenlist. same goes for if its
found in the odd list... move then delete.

now i've got it working almost exactly. I just cannot figure out how to
make it in alphabetical order.

my code can be found on

http://mandalicious.com/itzaprincess/program5.htm

beacuse i dont want to post all that code here.. its a lot.
so yes if anyone has any ideas on which way to point me on how to get
my oddlist and even lists sorted... i will love you forever and a day!
thank you

Susan

May 3 '06 #1
2 6986
* Su**********@gm ail.com:
Alright, I must say that the problem my teacher has given us to do has
royally annoyed me.
We are to take a letter *txt file* and then read in the words.

Make 2 seperate lists *even and odd* for the number of occurances...

so the first time a word is entered its going to have an occurance of
one and be in the odd list then it is going to go to the next word see
if its in the odd list. If its not its going to check the even list. if
its in the even list it will add one to the occurance move it to the
odd list and then take it out of the evenlist. same goes for if its
found in the odd list... move then delete.

now i've got it working almost exactly. I just cannot figure out how to
make it in alphabetical order.

my code can be found on

http://mandalicious.com/itzaprincess/program5.htm

beacuse i dont want to post all that code here.. its a lot.
so yes if anyone has any ideas on which way to point me on how to get
my oddlist and even lists sorted... i will love you forever and a day!
thank you


Are you sure that you have to have to implement the lists yourself?

The standard library provides std::list.

Also, are you sure it must be linked lists?

Because the execution time is then at best O(n^2) for n words.

Anyway, a few suggestions:

* Don't store data in the header node, let the header node be a
dummy node. That will simplify all of your code that currently
treats the header node as a special case.

* Try to remove all dead code, e.g. MAX_length and (it seems)
SortedList::dat a.

* Instead of member functions that modify their arguments, try to have
all arguments 'const' and return whatever the returned information is,
via the function result.

I know, this isn't going to help you sort, unless you can use std::list.

But it's going to significantly reduce the amount of work needed to
implementent sorting (which you can do by inserting each new word in its
sorted position).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 3 '06 #2
<Su**********@g mail.com> wrote in message
news:11******** *************@g 10g2000cwb.goog legroups.com...
: Alright, I must say that the problem my teacher has given us to do has
: royally annoyed me.
: We are to take a letter *txt file* and then read in the words.
:
: Make 2 seperate lists *even and odd* for the number of occurances...
....
: now i've got it working almost exactly. I just cannot figure out how to
: make it in alphabetical order.

Sorting linked lists is best achieved with the MergeSort algorithm:
http://en.wikipedia.org/wiki/Merge_sort
Of course, this is implemented by std::list::sort if you can use
standard library containers...

hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com
May 3 '06 #3

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

Similar topics

270
3990
by: Jatinder | last post by:
I found these questions on a web site and wish to share with all of u out there,Can SomeOne Solve these Porgramming puzzles. Programming Puzzles Some companies certainly ask for these things. Specially Microsoft. Here are my favorite puzzles. Don't send me emails asking for the solutions.
5
5501
by: Daniel | last post by:
I need to reverse the doubly linked list with dummy node. I think the solution is to exchange each node pointers' next and previous address. But what's wrong in my function? Thanks void reverse_list(NodePtr p) { NodePtr next, q=p, head=p->prev; while (q != head) { next = q->next; q->next = q->prev;
5
3225
by: free2cric | last post by:
Hi, how to detect head and tail in cyclic doubly link list ? Thanks, Cric
1
1796
by: drewy2k12 | last post by:
Heres the story, I have to create a doubly linked list for class, and i have no clue on how to do it, i can barely create a single linked list. It has to have both a head and a tail pointer, and each node in the list must contain two pointers, one pointing forward and one pointing backwards. Each node in the list will contain 3 data values: an item ID (string), a quantity (integer) and a price (float). The ID will contain only letters and...
4
4279
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event is stored in a double linked list, the whole list is sorted for the next round. My problem appears when subjecting the program to heavy load, that is, when I run the simulation for more than 10,000 miliseconds (every event occurs in...
3
2663
by: maruf.syfullah | last post by:
Consider the following Class definitions: class AClass { int ai1; int ai2; public: CClass* c; AClass(){}
10
1968
by: kalar | last post by:
Hello. we have this struct and we must to make a linked list struct node { char name; char phone; struct node *prevName; // previous node alphabetically struct node *prevNumber; // previous node sorted by numbers struct node *nextName; // next node alphabetically struct node *nextNumber; // next node sorted by numbers } ;
1
2347
by: Mahesh | last post by:
Hi Coders, I was asked to write a program to interchange numbers using doubly linked list @ Amazon. Here is the details with Code that i wrote. i/p: 1 2 3 4 5 6 7 8 .....n,n-1. o/p: 2 1 4 3 6 5 8 7.....n,n-1.
4
2931
by: arnuld | last post by:
This program follows from the section 6.5 of K&R2 where authors created a doubly-linked list using a binary-tree based approach. The only thing I have rewritten myself is the getword function. I am using it because there are many concepts involved in this program that I want to understand like: 1.) degree of efficiency of this program as compared to sort using hash-table based approach. 2.) Keeping the program well structured so...
0
8316
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,...
1
8509
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,...
0
8610
tracyyun
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...
0
7345
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, 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...
1
6174
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
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();...
0
4168
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...
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1730
bsmnconsultancy
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...

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.