473,695 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

circular list search

I created a circular linked list
whats the best way to search function for a name in the list and retrun that
node address
class PhoneBook
{
friend PhoneBookUserIn terface;
public:
PhoneBook();
~PhoneBook(){};
void add(PhoneBookRe c &pbr);
void remove(PhoneBoo kRec &pbr);
PhoneBookRec search(PhoneBoo kRec &key);
// PhoneBookRec get_rec(int i){return data[i];}
int get_number_of_e ntries();
void save(string filename);
void load(string filename);
private: //functions
void insertAfter(Lis tNode * pInsertAfterThi sNode, PhoneBookRec & pbr);
ListNode * findInsertionPt r(PhoneBookRec &pbr);
ListNode * findDeletePtr(P honeBookRec &pbr);
void deleteAt(ListNo de * pDeleteThisNode );
private: //variables
ListNode * pTop;
ListNode *pBottom;

};

#endif
Oct 8 '05 #1
3 2859
dave wrote:
I created a circular linked list
whats the best way to search function for a name in the list and retrun that
node address


This is hardly different to searching through any other list. You start
at the first node (pTop?) and you keep following ListNode::next pointers
until you either hit the end (i.e. you're back at the first node) or
until you find the key you're looking for.

Would you like to refine your question?

Jacques.
Oct 8 '05 #2
dave wrote:
I created a circular linked list
whats the best way to search function for a name in the list and retrun
that node address
class PhoneBook
{
friend PhoneBookUserIn terface;
public:
PhoneBook();
~PhoneBook(){};
void add(PhoneBookRe c &pbr);
void remove(PhoneBoo kRec &pbr);
PhoneBookRec search(PhoneBoo kRec &key);
// PhoneBookRec get_rec(int i){return data[i];}
int get_number_of_e ntries();
void save(string filename);
void load(string filename);
private: //functions
void insertAfter(Lis tNode * pInsertAfterThi sNode, PhoneBookRec & pbr);
ListNode * findInsertionPt r(PhoneBookRec &pbr);
ListNode * findDeletePtr(P honeBookRec &pbr);
void deleteAt(ListNo de * pDeleteThisNode );
private: //variables
ListNode * pTop;
ListNode *pBottom;

};

#endif


I would suggest not to roll your own code, but to use std::list, or maybe
std::map or std::multimap in the first place. Those container offer
anything you need to build a PhoneBook. So why would you want to dirty your
hands by touching raw pointers?
Best

Kai-Uwe Bux
Oct 9 '05 #3
dave wrote:

I created a circular linked list
whats the best way to search function for a name in the list and retrun that
node address


The 'best' way is the way you can solve that homework assignment.

--
Karl Heinz Buchegger
kb******@gascad .at
Oct 10 '05 #4

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

Similar topics

1
6469
by: dotnetnewbie | last post by:
Hi all I am new to .NET and webservice so I wish someone can shed some light on me. I have a Project class and a Product class, the Project can contain multiple Products (as an ArrayList). In my WebMethod I Initialize my project as following:
1
12839
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
23
2086
by: Rogers | last post by:
I want to compare strings of numbers that have a circular boundary condition. This means that the string is arranged in a loop without an end-of-string. The comparaison of two strings now becomes a different operation than with regular strings because the circular string can be "rotated", like this: 1 2 3 4 5 2 3 4 5 1 3 4 5 1 2 4 5 1 2 3
6
5071
by: Stephen Robertson | last post by:
We are currently in a dead end with a circular reference issue using vb.net, and are hoping someone might help us resolve it. Idea... We have frmmain calling frmperson (dim f as new frmperson) in search (no record) mode. When the search is executed, frmperson calls frmsearchresult (dim f as new frmsearchresult) which is a listing of persons. From frmsearchresults, frmperson is called (dim f as new frmperson) with the resulting...
3
7049
by: donnyma | last post by:
I have a problem that looks like it has not been discussed before in these groups. I have a simple SQLAgent job that runs sp_who (could be anything, but let's just say sp_who for this example). I have set the jobstep to write to an output file "T:\out.txt". If the job is owned by an admin, it runs fine and writes the output file. If it is owned by a non-admin user, it gets the following error msg: Warning: cannot write logfile...
12
15690
by: shivapadma | last post by:
please anyone tell me whether the following code works for checking the linked list is circular or not? address 0 address1 address2 | A|address1| |B|address2| |C|address0| | | | | ptr1 ptr2 A,B,C-are elements in list.
2
6447
by: sathishc58 | last post by:
Hi Can anyone explain me the difference between circular linked list and looped linked list? 1) In Circular linked list Next part of last node will be pointing to the first nodes starting address. 2) What is meant by loop then? Thanks & Regards Sathish Kumar
0
2818
balabaster
by: balabaster | last post by:
Hi, I have a couple of tables: Units( Unit_PKey Int Identity(1,1) Primary Key, Unit_Name nvarchar(8), Unit_Description nvarchar(32) )
3
2940
by: shapper | last post by:
Hello, On an ASP.NET MVC project I am getting a list of Tags which names start with a string contained on the variable "q". Everything works fine if no Post is related to Tags. When there is relation I start to get a Circular Reference error. I have been trying to solve this problem for days! I can't find the reason for this, either in my SQL or C# code.
0
8623
marktang
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...
0
9113
Oralloy
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...
0
8977
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7656
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
6488
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
5837
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
4577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2997
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
3
1971
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.