Linked List
A linked list is a data structure which is built from structures and pointers. It forms a chain of "nodes" with pointers representing the links of the chain and holding the entire thing together.
struct Node{
int data_;
Node* next_;
}
The important part of the structure is the line before the closing curly brackets. This gives a pointer to the next node in the list. This is the only case in C++ where you are allowed to refer to a data type (in this case node) before you have even finished defining it!
//if add node at the front
void addFront(int v){
Node* newnode = new Node;
newnode->data_ = v;
if(!start_){
start_ = newnode;
newnode->next_ = NULL;
}
else{
newnode->next_ = start_;
start_ = newnode;
}
}
//if add node at the end
void addEnd(int v){
NOde* temp, temp2;
temp = new Node;
temp->data- = v;
temp->next_ = NULL;
if(!start_) start_ = temp;
else{
temp2 = start_;
while(temp2->next_){
temp2 = temp2->next_;
}
temp2->next_ = temp;
}
}
Wednesday, July 7, 2010
Wednesday, June 23, 2010
C bitwise operator
~x + 1 = -x;
e.g. ~(-1) +1 = -(-1); that is ~(-1) = 0;
e.g. ~27 +1 = -27; that is ~27 = -28;
e.g. ~(-1) +1 = -(-1); that is ~(-1) = 0;
e.g. ~27 +1 = -27; that is ~27 = -28;
iofmain
test 9, testing insert key, the instruction says typing 'a' 'b' 'c', but actually it
accepts 'a' 'b' because it's longer than the maxlen, so if shows all, it failed.
accepts 'a' 'b' because it's longer than the maxlen, so if shows all, it failed.
Monday, June 21, 2010
bitwise operator
27&14
0001 1011
0000 1110
---------
0000 1010
only 1 & 1 is 1, any other is 0
in decimal, it's 10; in Hex, it's A
27|14
0001 1011
0000 1110
---------
0001 1111
only 0 | 0 is 0, any other is 1
in decimal, it's 31; in Hex, it's 1F
27^14
0001 1011
0000 1110
---------
0001 0101
if same 0, if different 1
in decimal, it's 21; in Hex, it's 15
so, if z = x^y; z^x = y; z^y = x;
0001 1011
0000 1110
---------
0000 1010
only 1 & 1 is 1, any other is 0
in decimal, it's 10; in Hex, it's A
27|14
0001 1011
0000 1110
---------
0001 1111
only 0 | 0 is 0, any other is 1
in decimal, it's 31; in Hex, it's 1F
27^14
0001 1011
0000 1110
---------
0001 0101
if same 0, if different 1
in decimal, it's 21; in Hex, it's 15
so, if z = x^y; z^x = y; z^y = x;
about C data type and bitwise operator
Q?1: How to case a char or int constant to short in C?
Q?2: How to case '\213' to unsigned char?
Q?3: Why float(4 bytes) allow 23 bits for mantissa since exponent occupied 8 bits,(sign takes one bit? but exponent takes 7 or 8 )
Q?4: %02x 0x stands for hexadecimal, but what is '2' for?
Q?5: why ~(-1) is 0, ~27 is -28, what is binary for '-' sign.
Q?2: How to case '\213' to unsigned char?
Q?3: Why float(4 bytes) allow 23 bits for mantissa since exponent occupied 8 bits,(sign takes one bit? but exponent takes 7 or 8 )
Q?4: %02x 0x stands for hexadecimal, but what is '2' for?
Q?5: why ~(-1) is 0, ~27 is -28, what is binary for '-' sign.
Monday, May 31, 2010
Visual Studio 2010
I have installed Visual Studio2010(ultimate) on my system. After successful installation, when I initialized it, I set it to project management. When I opened visual studio 2010 and tried to create new project, i did not see new project option on File menu. Finally, I found solution to it.
Go to Tools> Import Export Settings> Reset all settings> No> then choose vc++ other than project management
Go to Tools> Import Export Settings> Reset all settings> No> then choose vc++ other than project management
Wednesday, May 26, 2010
oop class today
Pointer is always an integer, and takes 4 bytes; but it points to different data types.
When pointer increase by 1, it moves to next address according different data types, like int adds 4, double adds 8.
When pointer increase by 1, it moves to next address according different data types, like int adds 4, double adds 8.
Subscribe to:
Posts (Atom)