473,854 Members | 1,857 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 16031
arne
315 Recognized Expert Contributor
how do I do this? pointers are not my good subjets lol
But you had it already (almost):

Expand|Select|Wrap|Line Numbers
  1. struct headernode{
  2.         char x;
  3.         listNodeType *next;
  4. }; 
  5.  
Replace listNodeType by ListNodeClass. Note that you have to change all access to a list, since you have an array of header structs now...
Oct 23 '06 #61
saraSS
69 New Member
going in circles here cant make it work with those pointers another way to do that?
Oct 23 '06 #62
arne
315 Recognized Expert Contributor
going in circles here cant make it work with those pointers another way to do that?
Since the vector has a constant number of elements, you could establish some mapping:

a is 0
b is 1
c is 2 and so on.

If you need set b, you know its the second (index 1) in your vector. But do not change the vector then or you will run in trouble ;-)

Alternatively, you could extend your nodes by another member. Instead of storing the identifier in a header you can store it in every node of the list. This is somewhat ugly, but you can go on with your current design ...
Oct 23 '06 #63
saraSS
69 New Member
I dont know nothing is working
Oct 23 '06 #64
saraSS
69 New Member
class ListNodeClass
{
private:
ItemType Info;
ListNodeClass * Next;
public:
// First, the constructor:
ListNodeClass(c onst ItemType & Item, ListNodeClass * NextPtr = NULL):
Info(Item), Next(NextPtr)
{
};
void GetInfo(ItemTyp e & TheInfo) const;
friend class ListClass; // very convenient to allow this
};

struct headernode
{
char x;
ListClass *next;
};

class ListClass
{
private:
ListNodePtr GetNode(const ItemType & Item,
ListNodePtr NextPtr = NULL);
void FreeNode(ListNo dePtr NodePtr);
void ClearList();
// Next 3 are sometimes made into protected fields:
ListNodePtr Front, Rear;
int Count;
public:
// constructor:
ListClass();
// destructor:
~ListClass();
int NumItems() const;
bool Empty() const;
void InsertRear(cons t ItemType & Item);
void printing();
ItemType RemoveFront();
ListNodePtr Find(const ItemType & Item) const;

};
int main()
{
int i,m;
char postfix[80];
char listname = 'a';

cin>>arraysize;
ListClass ListA[arraysize],*L;
L=ListA;
for( i = 0; i <arraysize; i++ )
{
while(cin>>numb er && number!=-1)
{
ListA[i].InsertRear(num ber);
}
cout<<ListA[i].NumItems()<<" ";
ListA[i].printing();
cout<<endl;
}
return 0;
}

this is almost what I have now and but cant make it work dont know why?and I have tried everyway you told me what I'm doing wrong
Oct 23 '06 #65
arne
315 Recognized Expert Contributor
this is almost what I have now and but cant make it work dont know why?and I have tried everyway you told me what I'm doing wrong
I have now used your code for a slim version. It's implementing a singly-linked, non-circular(!) list. All you can currently do is adding elements and print the content of the Info member.

Use this as a starting point. Extend the list with all features you need (circularity, removing nodes, ...).

Hope this is helpful :)


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. #define ItemType int
  7.  
  8. // the definition of a list node
  9. class ListNodeClass
  10. {
  11. public:
  12.     // the data of a node
  13.     ItemType Info;
  14.  
  15.     // the pointer to the next node
  16.     ListNodeClass *Next;
  17. };
  18.  
  19.  
  20. // the definition of a list (header!)
  21. class ListClass
  22. {
  23. private:
  24.         // entry to the list
  25.     ListNodeClass *Front;
  26.  
  27.     // number of elements
  28.     int Count;           
  29.  
  30.     // the ID to identify the set
  31.         char ID;  
  32.  
  33.     void FreeNode( ListNodeClass* );
  34.  
  35. public:
  36.     ListClass( char id ) : Front(0), Count(0), ID(id) {}
  37.  
  38.     void InsertFront( ListNodeClass& );
  39.     void InsertRear( ListNodeClass& );
  40.  
  41.     void RemoveFront();
  42.  
  43.     void ClearList();
  44.     int NumItems() const { return Count; }
  45.     bool Empty() const;
  46.     void Printing();
  47.  
  48.     ListNodeClass* Find(const ItemType & Item) const;
  49.  
  50. };
  51.  
  52. void ListClass::InsertFront( ListNodeClass& node ) {
  53.  
  54.     node.Next = Front;
  55.     Front = &node;    
  56.     Count++;
  57. }
  58.  
  59. void ListClass::Printing() {
  60.  
  61.     ListNodeClass *ptr = Front;
  62.  
  63.     cout << "This is set " << ID << " (" << Count << " elements): ";
  64.  
  65.     while( ptr!=NULL ) {
  66.  
  67.         cout << ptr->Info << " ";
  68.         ptr = ptr->Next;
  69.     }
  70.  
  71.     cout << endl;
  72. }
  73.  
  74. int main( void )
  75. {
  76.     ListNodeClass *node;
  77.  
  78.     // list a
  79.     ListClass list_a( 'a' );
  80.  
  81.     node = new ListNodeClass;
  82.     node->Info = 21;
  83.     list_a.InsertFront( *node );
  84.  
  85.     node = new ListNodeClass;
  86.     node->Info = 33;
  87.     list_a.InsertFront( *node );
  88.  
  89.     list_a.Printing();
  90.  
  91.     // list b
  92.     ListClass list_b( 'b' );
  93.  
  94.     node = new ListNodeClass;
  95.     node->Info = 3;
  96.     list_b.InsertFront( *node );
  97.  
  98.     node = new ListNodeClass;
  99.     node->Info = 2;
  100.     list_b.InsertFront( *node );
  101.  
  102.     node = new ListNodeClass;
  103.     node->Info = 1;
  104.     list_b.InsertFront( *node );
  105.  
  106.     list_b.Printing();
  107.  
  108.     return 0;
  109. }
  110.  
Oct 23 '06 #66
saraSS
69 New Member
thanks gonna try that
Oct 23 '06 #67
saraSS
69 New Member
looks like we were trying the same thing
I add 1 to the arraysize and try to put the letter in the first node but getting like 9 10 11 12 13 14 instead of a b c d e f how can I fix that? this is what I did

char listname = 97;

ListClass ListA[arraysize+1];

for( i = 1; i <arraysize+1; i++ )
{
while(cin>>numb er && number!=-1)
{
ListA[0].InsertRear((in t)listname++);
ListA[i].InsertRear(num ber);
}
cout<<ListA[i].NumItems()<<" ";
ListA[i].printing();
cout<<endl;
}
but getting
1st column the number of elemets of every cirlist
2nd is supose to be the a b c d e f
after that is every list
10 9 1 3 5 7 9 11 13 15 17 19
10 10 2 4 6 8 10 12 14 16 18 20
20 11 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
7 12 0 3 6 9 12 15 18
7 13 1 4 7 10 13 16 19
7 14 2 5 8 11 14 17 20
Oct 23 '06 #68
saraSS
69 New Member
I try 'a' instead of 97 and got the same also
Oct 23 '06 #69
arne
315 Recognized Expert Contributor
I try 'a' instead of 97 and got the same also
You try to store the list's identifier in a list element? Why? That's what the header struct (ListClass) is for. It stores the number of elements and the ID. The list nodes should only store the 'data' (Info member) and the 'Next' node pointer. When printing the list, you get the ID and the number of elements from the ListClass and the data from the ListNodeClass. Please have a look on the code I posted.

Or did I get you wrong?
Oct 24 '06 #70

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

Similar topics

1
12852
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
7
13531
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),...
3
7064
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
15714
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.
3
4146
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
2
6434
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;
5
3405
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)
0
2838
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) )
5
1429
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) {
0
9752
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,...
0
11041
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
10692
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...
1
10766
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
9525
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...
0
7083
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
5946
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4565
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
4167
muto222
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.