среда, 7 ноября 2012 г.

Challenge accepted :) 
             I've looked at what Amir and Saeid did, nice job, but I was wondering how you guys checked it if your code not even complied without doing this function modifiable with & sign.
             I decided to go a bit further and I did my operator[] method able to add new Nodes to the end of the Queue if we have index > size.
 Here is the code
int& Queue::operator[](unsigned int index){
  Node* temp = _head;
  int i;
  if (index >= _size) {
     while(index>=_size){
         int data = (_tail->_data/10)+(_head->_data/10);
         Node* newnode = new Node(data);
         _tail->_next = newnode;
         _tail = newnode;
         _size++;
     }
  }
  for (i = 0; i < index % _size; i++){
    temp = temp-> _next;
  }
  return temp-> _data;
}
---------------------------------------------------------
So then in the tester instead of:
for(i=0;Q.size();i++){
   cout<<Q[i]<<endl;
   Q[i] = Q[i] * 10;
  }

we have:
for(i=0;i<10;i++){
   cout<<Q[i]<<endl;
   Q[i] = Q[i] * 10;
  }
And it will continue add Nodes with valid data.
---------------------------------------------------------
Comments are welcome...

среда, 10 октября 2012 г.

Few questions were not clear for me, so I asked Fardad to clarify, maybe for somebody it will be usefull.
1)The user terminates editing by pressing ENTER, TAB, ESCAPE, UP, DOWN, PGUP, PGDN
How do I terminate it? by using system("pause"); ? and if user presses for example ENTER again he can continue typing?

2) If the user presses ESCAPE, your function aborts editing.
Does it mean that I am just returning string and cursor to it's original state?


Answers:

1) Termination happens but breaking the interface loop and returning the last key hit by user (int key).

2)
a) yes, you must do this by allocating memory to the size of the incoming string before editing begins and copying the content of str in it. Also you must create local variables holding the values of *strOffset and *curpos.
b) then make sure right before returning key at the end, you delete the allocated memory.
c) when  Escape is hit restore the value of str by copying back the data from allocated memory into str and setting the values of *strOffset and *curpos to their original values.