473,889 Members | 1,927 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 #1
103 16044
arne
315 Recognized Expert Contributor
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*'
May it be that you try to access the push member with code like
Expand|Select|Wrap|Line Numbers
  1.   obj[i].push();
  2.  
?

If so: the array contains only pointers to objects, not the objects themselves. So, you have to use
Expand|Select|Wrap|Line Numbers
  1.   (*obj[i]).push();
  2.  
or
Expand|Select|Wrap|Line Numbers
  1.   obj[i]->push();
  2.  
Oct 20 '06 #2
saraSS
69 New Member
fix that problem thatnks but still getting only one list I need different list my main is
int main( )
{
int i;
cin>>arraysize;
Linked_list_Sta ck *obj[arraysize];

for(i=0;i<array size;i++)
{
obj[i] = new Linked_list_Sta ck;
while(!cin.eof( ))
{
cin>>num;
if(num!=-1)
{
obj[i]->push( );
}
}
obj[i]->print_list( );
cout<<endl;
}
return 0;
Oct 20 '06 #3
arne
315 Recognized Expert Contributor
Could you please explain a little bit more in detail what you're trying to do?
As far as I understand from your code, you're

- building an array of pointers to elements of type Linked_list_Sta ck

- allocating objects for each of the pointers in the array

- invoking the member function push() of these objects (what is pushed here btw?)

- and finally you invoke the member function print_list (what will/should be printed here?)

Could you explain what should happen if you're program worked correctly?
Oct 20 '06 #4
saraSS
69 New Member
I im trying to implement a stack-based postfix calculator for sets of nonnegative
integers. The input consists of the following items:
a. n, the number of input sets, on a line by itself.
b. n ordered sets of non-negative integers, each starting on a new line and each terminated by -1. Each set is to be stored as an ordered, singly-linked,circular list with a header.
c. A string containing a postfix expression, on a line by itself, without any spaces. The following
may appear:
U set union (destructive, i.e. the result set will be created using some elements of the operand
sets. Extra elements must be recycled.)
I set intersection (destructive)
- set difference (destructive)
\ symmetric difference (destructive)
= equality test (destructive)
< tests whether the first operand set is properly contained in the second operand set (destructive)
& Boolean and (implementation of TRUE/FALSE is your decision)
| Boolean or
! Boolean not
x where x is a lower-case symbol in the range ‘a’ . . . ‘z’ to indicate that a copy should be made
of an input set. This copy will be an ordered singly-linked circular list with a header. A
pointer to the header of the cloned list is to be pushed to the stack. ‘a’ indicates that the first
input set should be copied, ‘b’ indicates that the second input set should be copied, and so on.
The input will be provided to your program through standard input using a shell redirect.
2. The output is the one item that remains on the stack after processing the entire postfix expression. It
may be a set (e.g. a linked list) or a Boolean value. If it is a set, then print the values separated by
spaces. If it is a Boolean value, then print TRUE or FALSE.

one example input file is
6
1 3 5 7 9 11 13 15 17 19 -1
2 4 6 8 10 12 14 16 18 20 -1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 -1
0 3 6 9 12 15 18 -1
1 4 7 10 13 16 19 -1
2 5 8 11 14 17 20 -1
abcdefUUUUIabIa cIadIaeIafIUUUU =

what I have done is just the link list my program

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7. int arraysize,num;
  8.  
  9. class Linked_list_Stack
  10. {
  11. private:
  12. struct node
  13. {
  14. int data;
  15. node *next;
  16. };
  17.  
  18. node *top;
  19. node *entry;
  20. node *print;
  21. node *bottom;
  22. node *last_entry;
  23. node *second_last_entry;
  24.  
  25. public:
  26. Linked_list_Stack( );
  27. void pop( );
  28. void push( );
  29. void print_list( );
  30. void show_working( );
  31. };
  32.  
  33. Linked_list_Stack::Linked_list_Stack ( )
  34. {
  35. top=NULL;
  36. bottom=NULL;
  37. }
  38.  
  39. void Linked_list_Stack::push( )
  40. {
  41.  
  42. entry=new node;
  43. if(bottom==NULL)
  44. entry->data=num;
  45. entry->next=NULL;
  46. bottom=entry;
  47. top=entry;
  48. }
  49. else
  50. {
  51. entry->data=num;
  52. entry->next=NULL;
  53. top->next=entry;
  54. top=entry;
  55. }
  56. cout<<"\n\n\t *** "<<num<<" is pushed onto the Stack."<<endl;
  57. }
  58.  
  59. void Linked_list_Stack::pop( )
  60. {
  61. if(bottom==NULL)
  62. cout<<"\n\n\n\t *** Error : Stack is empty. \n"<<endl;
  63. else
  64. {
  65. for(last_entry=bottom;last_entry->next!=NULL;
  66. last_entry=last_entry->next)
  67. second_last_entry=last_entry;
  68. if(top==bottom)
  69. bottom=NULL;
  70.  
  71. int poped_element=top->data;
  72. delete top;
  73. top=second_last_entry;
  74. top->next=NULL;
  75. cout<<"\n\n\n\t *** "<<poped_element<<" is poped from the Stack."<<endl;
  76. }
  77. }
  78.  
  79. void Linked_list_Stack::print_list( )
  80. {
  81. print=bottom;
  82.  
  83. if(print!=NULL)
  84. cout<<"\n\n\n\n\n\t Values pushed onto Stack are : \n"<<endl;
  85.  
  86. while(print!=NULL)
  87. {
  88. cout<<print->data;
  89. print=print->next;
  90. }
  91. }
  92.  
  93. int main( )
  94. {
  95. int i;
  96. cin>>arraysize;
  97. Linked_list_Stack *obj[arraysize];
  98.  
  99. for(i=0;i<arraysize;i++)
  100. {
  101. obj[i] = new Linked_list_Stack;
  102. while(!cin.eof()) 
  103. cin>>num;
  104. if(num!=-1)
  105. {
  106. obj[i]->push( );
  107. }
  108. }
  109. obj[i]->print_list( );
  110. cout<<endl;
  111. return 0;
  112. }
  113.  
thanks for helping me
Oct 20 '06 #5
saraSS
69 New Member
did I scare you off I hope not I need some help mostly with the lists I have some code ready for the operations between the list mean the union and all that
thanks again
Oct 20 '06 #6
arne
315 Recognized Expert Contributor
did I scare you off I hope not I need some help mostly with the lists I have some code ready for the operations between the list mean the union and all that
thanks again
No, you didn't. It was just night time where I live, so I had to get some sleep :-)

Do you need to build the lists/stacks on your own (for instance, since it is part of the assignment)? If not, you may consider to use the "list" and "stack" containers from the C++ standard template library. This would save you a lot of trouble, I guess.
Oct 21 '06 #7
saraSS
69 New Member
ok that sound good but how do I do that ?
Oct 21 '06 #8
arne
315 Recognized Expert Contributor
ok that sound good but how do I do that ?
:)
Start off with getting a good introductory book / tutorial on C++: the template containers are explained in each of these. It's really worth the effort!

For a quick start, you can also have a look at
http://www.cppreferenc e.com
They explain the usage of containers with easy examples and list all member functions to manipulate them.
Oct 21 '06 #9
saraSS
69 New Member
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
Oct 21 '06 #10

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

Similar topics

1
12855
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
13533
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
7068
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
15718
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
4147
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
3406
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
1430
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
9969
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
9810
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
10794
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
10896
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
10443
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
7151
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
5830
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...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4650
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 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.