473,889 Members | 1,654 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
saraSS
69 New Member
It looks like I get that wrong also I need an 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.
Oct 24 '06 #71
arne
315 Recognized Expert Contributor
It looks like I get that wrong also I need an 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.
You mean you don't understand this or your implementation doesn't work?
Oct 24 '06 #72
saraSS
69 New Member
I did not understand this part before and was trying something harder that what is suppose to be but the pointer thing still messing me up
Oct 24 '06 #73
saraSS
69 New Member
what I'm trying to do now is a stackclass where i'm gonna have all the fuction to use with the stacklike this
class stackClass
{
public:
stackClass();// constructor:
~stackClass();// destructor:
void Initialize();
void SetExpression(c har *str);
void Push(char c);
char Pop();
void Evaluate();
};

and when I'm evalueting the expression I check for the letter and make a copy
'maybe'
l=strlen(eval);
ListNodePtr tmp;
for(i=0;i<l;i++ )
{
if(eval[i]>=97 && eval[i]<=122)
{
//tmp=CopyList(ev al[i]);
Push(eval[i]);
cout<<eval[i];
}
else
{
A=Pop( );
B=Pop( );
switch(eval[i])
{
case 'U': break;
case 'I': break;
case '-': break;
}
what do you thing?
Oct 24 '06 #74
arne
315 Recognized Expert Contributor
what I'm trying to do now is a stackclass where i'm gonna have all the fuction to use with the stacklike this
I think you're trying to write too much code on your own. As far as I can see the assignment does not prevent you from using the std::stack from STL, does it? So, you don't have to implement a stack class on your own, it's already there!
Oct 24 '06 #75
saraSS
69 New Member
how can I do that ? the easy way then?
Oct 24 '06 #76
arne
315 Recognized Expert Contributor
how can I do that ? the easy way then?
Here comes an example on how to use a stack. You can insert it at the end of the program I posted some posting ago ... you know, the one with list_a and list_b ...

Expand|Select|Wrap|Line Numbers
  1.     ListClass *tmp_list_ptr;
  2.  
  3.     // define a std::stack
  4.     stack<ListClass *> op_stack;
  5.  
  6.     // get the number of elems on the stack
  7.     cout << "Stack elements:" << op_stack.size() << endl;
  8.  
  9.     // push elems onto the stack
  10.     op_stack.push( &list_b );
  11.     op_stack.push( &list_a );
  12.  
  13.     cout << "Stack elements after 2x push:" << op_stack.size() << endl;
  14.  
  15.     // get the top element
  16.     tmp_list_ptr = op_stack.top();
  17.     cout << "No. of elems in top list: " << tmp_list_ptr->NumItems() 
  18.          << endl;
  19.     cout << "Stack elements after top():" << op_stack.size() << endl;
  20.  
  21.     // remove the top element
  22.     op_stack.pop();
  23.     cout << "Stack elements after pop():" << op_stack.size() << endl;
  24.  
Oct 24 '06 #77
saraSS
69 New Member
good gonna try that thanks
Oct 24 '06 #78
saraSS
69 New Member
Your example looks look but does not work with my array of circular list or at least I dont know how to make it work so stuck again but i guess everybody in my class is having problem because we got more time I'm gonna try to leave the array in main just to create the set of circular list and in my funtion evaluation want to do the expresion evaluarion as a stack based postfix
like this
int main()
{
ListNodeClass *node;
ListClass *tmp_list_ptr;
int i;

cin>>arraysize;
ListClass list[arraysize];

for(i=0;i<array size;i++)
{
while(cin>>numb er && number!=-1)
{
node = new ListNodeClass;
node->Info = number;
list[i].InsertFront(*n ode);
}
cout<<list[i].NumItems()<<" ";
list[i].Printing();
cout<<endl;
}
Evaluate();

return 0;
} and for the evaluation

void Evaluate()
{
int i,l,A,B,Q,Z;
char postfix[80];
stack<ListClass *> op_stack;
ListNodeClass *tmp,*e[arraysize];

cin.getline (postfix,80);
SetExpression (postfix);
cout<<"ok";
puts(postfix);
cout<<"ok";
strcpy(eval,pos tfix);
cout<<"ok";
puts(eval);
cout<<"ok";
l=strlen(eval);
for(i=0;i<l;i++ )
{
if(eval[i]>=97 && eval[i]<=122)
{
e=eval[i];
tmp=CopyList(e[i]);
op_stack.push(e val[i]);
cout<<eval[i];
}
else
{
switch(eval[i])
{
case 'U': break;
case 'I': break;
case '-': break;
//case '\'' : break;
case '<' : break;
case '&' : break;
case '|' : break;
case '!' : break;
}
//op_stack.push(Q );
}
}
op_stack.pop();
} but getting some errors
dont know what to do
?
Oct 25 '06 #79
arne
315 Recognized Expert Contributor
So, as far as I understand. If you got all things running (i.e. the creation of the array with the singly-linked circular list), you start to evaluate the expression by scanning it and performing the required action.

So for the sample expression abcdefUUUUIabIa cIadIaeIafIUUUU = from your assignment, you push pointers to the lists (IMHO it would be sufficient to use the list identifier, but anyway) onto your stack, so if you reach the first 'U', your stack should look like

f e d c b a

with the top element on the left.

U means set union, so you got to unite the top 2 elements (i.e. lists on your stack). The result is the new top element, so after the U the stack looks like

f+e d c b a

I would say (correct me if I get things wrong here).

So, what you need to do technically is to invoke a routine to unite two lists :-) You may also need to allocate some result list, where you store the temporary result of the last operation (for the f+e list in the example above). The pointer to this temp result is pushed onto your stack.

The lists in your array should not be changed as they're needed for reference in later operations ...
Oct 26 '06 #80

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
11203
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
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
9612
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
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...
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
2
4251
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.