C++ Experts?

Marcello

Capitano
Capitano
Joined
Dec 3, 2005
Messages
4,737
Likes
8
Favorite Player
J.Cesar
10 years of FIF
Hi everyone , this forums is huge and i need some help , does anyone know anything to do with Stacks and linked lists/arrays?

lol this is a bit random but am very desperate

Thankyou

Forza Inter!
 

king_elnino

Capitano
Capitano
Joined
Jul 6, 2011
Messages
1,997
Likes
223
Favorite Player
Javier Zanetti
10 years of FIF
give your code here, i'll see what can i do for you :)
 

Fitzy

La Grande Inter
La Grande Inter
Joined
Aug 21, 2009
Messages
12,419
Likes
3,875
Favorite Player
Zanetti
Forum Supporter
Most Humorous Member
10 years of FIF
What are you stuck with?
 

Marcello

Capitano
Capitano
Joined
Dec 3, 2005
Messages
4,737
Likes
8
Favorite Player
J.Cesar
10 years of FIF
wow that was quick responses thanyou :) ok so heres the problem , ill need help on the code but the problem is the worst part

well theres a problem to the question i have, i need to implement it with stacks (push,pop,top)

but this is the idea it is :(


 

Pajo

Moderator
Moderator
Joined
Apr 8, 2006
Messages
38,755
Likes
287
Favorite Player
Sergio Aguero!
10 years of FIF
Why do people still use C++ for lists and arrays...? Java is the language for that, no pointers (well everything IS pointer, but you dont specify it). It's much easier to use Java for this job than c++...
 

Marcello

Capitano
Capitano
Joined
Dec 3, 2005
Messages
4,737
Likes
8
Favorite Player
J.Cesar
10 years of FIF
Why do people still use C++ for lists and arrays...? Java is the language for that, no pointers (well everything IS pointer, but you dont specify it). It's much easier to use Java for this job than c++...

pajoo!!!! :)

im just a bigginer mate , ill work my way up to java once i can get through this.. i hate pointers lol

---------- Post added at 21:29 ---------- Previous post was at 21:26 ----------

plajm.jpg

  • The Train can drive in or out of “(T1),(T2)” Forward or Backwards
  • The Train can be disconnected between 2 “Cargos”
  • A cargo can be parked temporally in (T1),(T2) , but not on the main track!
  • A cargo cannot move without the engine
 

Pajo

Moderator
Moderator
Joined
Apr 8, 2006
Messages
38,755
Likes
287
Favorite Player
Sergio Aguero!
10 years of FIF
That's the thing, you dont NEED to learn C++ to learn java. It's better for understanding lists though. :)

And you, i was wondering if you are alive. Where the fuck have you been? :D

As for the problem, i havent touched c++ for over 3 years, so i can hardly be of any help. Sry :) I could explain what i'd do, but cant give you the code. Maybe elnino or fitzy can :)
 

Marcello

Capitano
Capitano
Joined
Dec 3, 2005
Messages
4,737
Likes
8
Favorite Player
J.Cesar
10 years of FIF
That's the thing, you dont NEED to learn C++ to learn java. It's better for understanding lists though. :)

And you, i was wondering if you are alive. Where the fuck have you been? :D

As for the problem, i havent touched c++ for over 3 years, so i can hardly be of any help. Sry :) I could explain what i'd do, but cant give you the code. Maybe elnino or fitzy can :)

lol your funy man , iv been here just not signed in lol thanks for asking :)


aww comon pajo help me bro.. can i use a vector & stack would that be easier


i just have to get 5 numbers randomly 4,3,5,1,2 , doesnt matter how they are numbered , and they have to go into 2 junctions (t1,t2) to get sorted using stacks when they come out of the junction they must be re ordered to 1,2,3,4,5

simple :) ?
 

blackmore

8|G 8055
La Grande Inter
Joined
Sep 15, 2004
Messages
14,623
Likes
3
Favorite Player
SE SALTELLI....
why take the train, when u can fly?

:eek:blivious:
 

Pajo

Moderator
Moderator
Joined
Apr 8, 2006
Messages
38,755
Likes
287
Favorite Player
Sergio Aguero!
10 years of FIF
Yeah. The main tracks should be implemented with double linked lists, i think it is the best. The t1 and t2 with stacks. If the train is parked, and another comes in, i guess the second that came must get out first, and than the other, that;s the stack.

What is the engine actually, some value? If so, than the "train" must start with that value, which will represent the engine. For disconnecting trains, you will need a function that separates one big list in two or more smaller ones. As for the aprking, i have no idea how to make it :D
 

La Brujita

Capitano
Capitano
Joined
May 18, 2007
Messages
2,714
Likes
0
Favorite Player
J.Zanetti
Forum Supporter
10 years of FIF
I haven't done proper programming in quite a while now :(

Just some websites.

I remember a bit about linked lists and stacks. I can't remember well, if no one comes to help I'll try and help but you can also post in websites like stackoverflow to get good answers for these questions
 

Marcello

Capitano
Capitano
Joined
Dec 3, 2005
Messages
4,737
Likes
8
Favorite Player
J.Cesar
10 years of FIF
Yeah. The main tracks should be implemented with double linked lists, i think it is the best. The t1 and t2 with stacks. If the train is parked, and another comes in, i guess the second that came must get out first, and than the other, that;s the stack.

What is the engine actually, some value? If so, than the "train" must start with that value, which will represent the engine. For disconnecting trains, you will need a function that separates one big list in two or more smaller ones. As for the aprking, i have no idea how to make it :D


I have only done linked lists and arrays based stacks

but theres only one train and 2 stacks, and the engine can move backwards and forwards , pretty much the engine is what makes the stack work and the engine always has to be in front , so i dont know how the hell im going to code that , wow this is so hard
 

king_elnino

Capitano
Capitano
Joined
Jul 6, 2011
Messages
1,997
Likes
223
Favorite Player
Javier Zanetti
10 years of FIF
You need pointer to solve next and back..
 

Marcello

Capitano
Capitano
Joined
Dec 3, 2005
Messages
4,737
Likes
8
Favorite Player
J.Cesar
10 years of FIF
ok , so would code like this be good for my problem?
or maybe not?


Code:
// This program demonstrates the DynIntQeue class.
#include <iostream>
#ifndef DYNINTQUEUE_H
#define DYNINTQUEUE_H
using namespace std;

////////////////////////////////////////////////////////////////////////
class DynIntQueue
{
private:
   // Structure for the queue nodes
   struct QueueNode
   {
      int value;       // Value in a node
      QueueNode *next; // Pointer to the next node
   };
   QueueNode *front;  // The front of the queue
   QueueNode *rear;   // The rear of the queue
   int numItems;      // Number of items in the queue 
public:
   // Constructor
   DynIntQueue();
   // Destructor
   ~DynIntQueue();
   // Queue operations
   void enqueue(int);
   void dequeue(int &);
   bool isEmpty() const;
   bool isFull() const;
   void clear();
};
////////////////////////////////////////////////////////////////////////
 

//**************************************************
// Destructor                                      *
// This function deletes every node in the list.   *
//**************************************************
 DynIntStack::~DynIntStack()
{
   StackNode *nodePtr, *nextNode;
   // Position nodePtr at the top of the stack.
   nodePtr = top;
   // Traverse the list deleting each node.
   while (nodePtr != NULL)
   {
      nextNode = nodePtr->next;
      delete nodePtr;
      nodePtr = nextNode;
   }
}
//************************************************
// Member function push pushes the argument onto *
// the stack.                                    *
//************************************************
void DynIntStack::push(int num)
{
   StackNode *newNode; // Pointer to a new node
   // Allocate a new node and store num there.
   newNode = new StackNode;
   newNode->value = num;
   // If there are no nodes in the list
   // make newNode the first node.
   if (isEmpty())
   {
      top = newNode;
      newNode->next = NULL;
   }
   else  // Otherwise, insert NewNode before top.
   {
      newNode->next = top;
      top = newNode;
   }
}
//****************************************************
// Member function pop pops the value at the top     *
// of the stack off, and copies it into the variable *
// passed as an argument.                            *
//****************************************************
void DynIntStack::pop(int &num)
{
   StackNode *temp; // Temporary pointer
   // First make sure the stack isn't empty.
   if (isEmpty())
   {
      cout << "The stack is empty.\n";
   }
   else  // pop value off top of stack
   {
      num = top->value;
      temp = top->next;
      delete top;
      top = temp;
   }
}
//****************************************************
// Member function isEmpty returns true if the stack *
// is empty, or false otherwise.                     *
//****************************************************
bool DynIntStack::isEmpty()
{
   bool status;
   if (!top)
      status = true;
   else
      status = false;
   return status;
}
///////////////////////////////////////////////////////////////////////////////
 
 
int main()
{
   const int MAX_VALUES = 5;
   // Create a DynIntQueue object.
   DynIntQueue iQueue;
   // Enqueue a series of numbers.
   cout << "Enqueuing " << MAX_VALUES << " items...\n";
   for (int x = 0; x < 5; x++)
      iQueue.enqueue(x);
   
   // Dequeue and retrieve all numbers in the queue
   cout << "The values in the queue were:\n";
   while (!iQueue.isEmpty())
   {
      int value;
      iQueue.dequeue(value);
      cout << value << endl;
   }
   system("pause");
   return 0;
}


---------- Post added at 17:17 ---------- Previous post was at 17:16 ----------

Also i cant even get that above code to work ^
 

Marcello

Capitano
Capitano
Joined
Dec 3, 2005
Messages
4,737
Likes
8
Favorite Player
J.Cesar
10 years of FIF
Yeah. The main tracks should be implemented with double linked lists, i think it is the best. The t1 and t2 with stacks. If the train is parked, and another comes in, i guess the second that came must get out first, and than the other, that;s the stack.

What is the engine actually, some value? If so, than the "train" must start with that value, which will represent the engine. For disconnecting trains, you will need a function that separates one big list in two or more smaller ones. As for the aprking, i have no idea how to make it :D

aww thanks man

theres only 1 train so just a single linked list? and ye the engine must be there , it must be the engine to collect the values in the stacks and move them from one to the other


would you know how to code the stacks ? for 2 stacks? thats the hard part for me
 

Pajo

Moderator
Moderator
Joined
Apr 8, 2006
Messages
38,755
Likes
287
Favorite Player
Sergio Aguero!
10 years of FIF
I told you, didnt work c++ for long long time, and never using stacks on it :) Not lists as well, never learned pointers like i should lol :D

As for the train.. Hmm, yeah, you could use linked list only. I told you double linked because i thought the train could move both ways, didnt see that there is "entrance" and "exit". So yeah, SLL would be ok.
 

Marcello

Capitano
Capitano
Joined
Dec 3, 2005
Messages
4,737
Likes
8
Favorite Player
J.Cesar
10 years of FIF
anybody know anything about binary trees :)?
 

Pajo

Moderator
Moderator
Joined
Apr 8, 2006
Messages
38,755
Likes
287
Favorite Player
Sergio Aguero!
10 years of FIF
In Java yes, in c++, not really :p
 

Pajo

Moderator
Moderator
Joined
Apr 8, 2006
Messages
38,755
Likes
287
Favorite Player
Sergio Aguero!
10 years of FIF
I cant do it because its done with pointers in c++, i think. And i have never learned those pointers when i should have. In hava pointers are not needed, they are implemented in everything.. So, i cant help you :)
 
Top