473,889 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

circular link list in c++

69 New Member
I'm trying to built and array of circular link list but when I read the input file Ijust get a long link list instead of different list and after trying to use Linked_list_Sta ck *obj[arraysize]; I'm getting this errors
newcir.cpp:107: request for member `push' in `obj[i]', which is of
non-aggregate type `Linked_list_St ack*'
newcir.cpp:110: request for member `print_list' in `obj[i]', which is of
non-aggregate type `Linked_list_St ack*'
Oct 20 '06
103 16044
69 New Member
for example I have the class

Expand|Select|Wrap|Line Numbers
  2. class list
  3. {
  4. public:
  5. node* begin() const;
  6. node* end() const;
  7. int size() const;
  8. bool empty() const;
  9. void insert(node* p, const data_type& d);
  10. void erase(node*& p);
  11. list();
  12. list (const list& l);
  13. ~list();
  14. list& operator= (const list& l);
  15. private:
  16. void free_list();
  17. node* head;
  18. #define tail NULL
  19. };
then I need to implement some code from the site you gave me for every function I have in this class? and what about the ones that dont have an implementation they dont need implementation because I'm adding #include <list> ?
see I'm really confuse
Oct 21 '06 #11
315 Recognized Expert Contributor
in the site you gave me talk a lot about vector can I use the same functions for my list and I'll need to change all my program for some of those functions I dont know I'm confuse
The question was if you _have_ to implement the containers (i.e. data structures such as list or stack) on your own or if you may want to use the built-in classes.

It is nothing wrong with implementing and using one's own data structures, as long as you have a good reason to do so.

Using the STL containers was just a proposal that may save you some time now (since you don't need to worry about how to implement and debug your data structures) and later (as you know about STL containers next time you have to do some coding).

I am sorry if I confused you :)
Oct 21 '06 #12
69 New Member
I want to save some time and learn to use the stl but getting confuse here
Oct 21 '06 #13
315 Recognized Expert Contributor
I want to save some time and learn to use the stl but getting confuse here
Upps, sorry didn't see your last post ... that's why I replied to an old posting by you ...

You don't have to implement the member functions of the STL list, it's already done. The STL list contains all functions you typically need for a list, such as inserting elements, finding elements, removing elements and the like. The same holds true for the stack container.
Look at the "Constructo rs" to see how objects of these classes can be created.

In addition, there are some (generic) algorithms, such as copy, sort, rotate and many more that support operations on STL containers. See the "Algorithms " section on the site I mentioned.
Oct 21 '06 #14
69 New Member
then if the fuction are in the stl I dont need to include then in my class? if I include then means I need to implement them?

do I need just to work in main and call for all those functions when I need them?
Oct 21 '06 #15
315 Recognized Expert Contributor
then if the fuction are in the stl I dont need to include then in my class? if I include then means I need to implement them?

do I need just to work in main and call for all those functions when I need them?
Yes, you just include the header. I attach a simple example that uses the STL list container and an STL algorithm:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <list>
  4. using namespace std;
  6. int main( void )
  7. {
  8.     // define a list that holds ints
  9.     list<int> i_list;
  11.     // add new elements at the end of the list (list member function)
  12.     i_list.push_back( 1 );
  13.     i_list.push_back( 2 );
  14.     i_list.push_back( 3 );
  15.     i_list.push_back( 4 );
  17.     // traverse the list and print out the elements
  18.     list<int>::iterator iter;
  19.     for( iter=i_list.begin(); iter!=i_list.end(); iter++ ) {
  21.         cout << *iter << endl;
  22.     }
  24.     // reverse the list (generic STL algorithm)
  25.     reverse( i_list.begin(), i_list.end() );
  27.     // traverse the list and print out the elements (again)
  28.     for( iter=i_list.begin(); iter!=i_list.end(); iter++ ) {
  30.         cout << *iter << endl;
  31.     }
  33.     return 0;
  34. }
Oct 21 '06 #16
69 New Member
then yes this way save a lot time .
I trying to make various containers using an array like

list<int> i_list[arraysize];

and use a for loop like this

Expand|Select|Wrap|Line Numbers
  2. for(i=0;i<arraysize;i++)
  3. {
  4. while(!cin.eof())
  5. {
  6. cin>>num;
  7. if(num!=-1)
  8. {
  9. i_list[i].push_back( num );
  10. }
  11. else
  12. return 0;
  13. }
  15. and printing out like this
  17. for(i=0;i<arraysize;i++)
  18. {
  19. // traverse the list and print out the elements
  20. list<int>::iterator iter;
  21. for( iter=i_list[i].begin(); iter!=i_list[i].end(); iter++ )
  22. {
  23. cout << *iter << endl;
  24. }
I'm not getting errors just blank
Oct 21 '06 #17
69 New Member
opps was not readding the size of the array now I got
-bash-2.05b$ a.out < hw2file1.txt
how can I rewrite the while loop so it stops every -1 and keep going with the array of containers ?
Oct 21 '06 #18
69 New Member
I got it working the list
I guess you when home? ok thanks

do you think this is gonna work as circular list or I need an extra funtion just to make every list a circular lis you know making the end point to the head ?
Oct 21 '06 #19
315 Recognized Expert Contributor
I got it working the list
I guess you when home? ok thanks

do you think this is gonna work as circular list or I need an extra funtion just to make every list a circular lis you know making the end point to the head ?
Do you really need a circular list?
Oct 21 '06 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

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
by: barias | last post by:
Although circular dependencies are something developers should normally avoid, unfortunately they are very easy to create accidentally between classes in a VS project (i.e. circular compile-time dependencies). But then I started wondering how "easy" it would be to similarly make a NON-RUNTIME circular dependency between (implicitly linked) DLLs. Indeed authors like John Lakos, who focus on compile/link-time dependencies (not run-time),...
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...
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.
by: Giampaolo Rodola' | last post by:
Hi there, I would like to know if such function would be correct for verifying if a link is broken and/or circular. def isvalidlink(path): assert os.path.islink(path) try: os.stat(path) except os.error: return 1
by: morris11 | last post by:
I am trying to create a circular list that includes insert() , find() and remove() methodes. also a step() method that moves current along to the next link. I still need to display the list by breaking the circle at some arbitrary point to print it on the screen. Does anyone have an idea how to do that? import javax.swing.JOptionPane; public class CLL { public class Link { int item=0; Link next;
by: =?Utf-8?B?Qm9i?= | last post by:
I have a table of dependencies and want to check to see if the dependencies cause a circular reference. Any sugesstions on how to do this using c#. Example, ID DependsOnID 1 2 1 4 2 3 3 1 (circular reference)
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) )
by: Muzammil | last post by:
i have problem with this operator "+" in doubly circular link list.(i think i have problem with return type). error is of instantiate error.(mean type dismatch) if any one can help me please reply. template <class T> DoublyCircularLinkList<TDoublyCircularLinkList<T>:: operator + (const DoublyCircularLinkList& rhs) { if (head==0 && rhs.head==0) {
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: 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: 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...
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: 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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.