HuggableAtol
BAN USERnot sure this is efficient but Doubly Linkedlist with additional capability(See below) could solve the problem:
Consider:
------C1 -- C2 -- C3
================
R1 || L1 -- L2 -- L3
.......||....|........|.........|
R2 || L4 -- L5 -- L6
.......||....|.........|........|
R3 || L7 -- L8 -- L9
The above diagram clearly explains L1 points L2 (next/prev element in row) and L3 (next/prev element in the column) and so on .
so the linkedlist class will be:
class node{
int data;
node *rowNext;
node *columnNext;
node *rowPrev;
node *columnPrev;
void delete row();
void delete column();
void delete element(){
//this one is tricky but a count of indices would make the deletion simpler along with updating the next elements in the current and adjacent row/column;
}
-to delete a column use columnNext to free the memory and update the rowPrev node's address everytime.
-to delete a row use rowNext free the memory and update the columnPrev node's address
-to delete an arbitrary element complex procedure [Update next and adjoint elements -- Creating a function would solve the problem]
****************************************
for the second part of the problem there is something called as DDEML (Dynamic Data Exchange Management Library).
Overriding:
A method with same name, signature, arguments, return type defined in Super class and Sub class. Out of the two methods the subclass method is executed. This is achieved by declaring VIRTUAL the function Virtual.
Example:
class Parent{
virtual int child(){};
}
class Child: Parent {
int child(){};
}
Overloading:
This is basically overloading of a particular function achieved by varying the number/data type of arguments.
Example :
int area (int r) {};
int area(int a, int b) {};
Stack:
Slot # = 1 2 3 4 5… n
All slots are free currently....
FreeStack = n n-1 n-2 n-3….. 1 // Note its the reverse of Slot # which are free
-------------------------------- Arrivals----------------
1st car – Slot 1
FreeStack.Pop()
.
.
Nth car – Slot N
FreeStack.Pop()
ParkingFull =1;
------------------------------------------Car Leaving----------------------------------------------
Car at Slot #‘i1’ leaves:
FreeStack.Push(i1); ParkingFull =0;
.
.
Car Slot # ‘i8’ leaves:
FreeStack.Push(i8)
-------------------------------------------New car Arrives----------------------------------------
Goes to the Slot # pointed by the top of the stack (FreeStack.Top()).
FreeStack.Push();
O(1) Complexity..
Step 1: Do a pre-order traversal. and store the node values in an array.
- HuggableAtol March 14, 2012Step 2: traverse in such a way that you store the values as the problem (kind of modified pre order).
Step 1:
void preorder (node * p){
if(root == (node*) NULL)
return;
a[i] = p-> data;
i++;
preorder(p->left_p);
preorder(p->right_p);
}
void modifiedPreorder (node * p) {
if(root == (node*) NULL)
return;
p-> data = a[i];
i++;
modifiedPreorder(p->right_p);
modifiedPreorder(p->left_p);
}