struct node{ int data; struct node *next; }; struct node *getLastNode(struct node *head); void insertNode(struct node **head, int data) { struct node *newNode = (struct node*)malloc(sizeof(struct node)); newNode->next = NULL; newNode->data = data; if(*head == NULL) { *head = newNode; } else { getLastNode(*head)->next = newNode; } } struct node *getLastNode(struct node *head) { struct node *lastNode = head; if(head == NULL) return NULL; else{ while(lastNode->next != NULL) lastNode = lastNode->next; } return lastNode; }
Showing posts with label Software Engineering. Show all posts
Showing posts with label Software Engineering. Show all posts
Insert Node into the end of list
[Easy Data Structure] Nice functions to traverse and find middle node in Singly Linked List
#include
#include
struct ListNode * InitLinkedList();
int PrintFromBeginning(struct ListNode *head);
int CheckOddorEvenLength(struct ListNode *head);
struct ListNode *FindMiddleNode(struct ListNode *head);
//#define NULL 0
struct ListNode{
int data;
struct ListNode *next;
};
struct ListNode * InitLinkedList()
{
struct ListNode *head = malloc(sizeof(struct ListNode));
struct ListNode *node1, *node2, *node3, *node4;
struct ListNode *newNode = malloc(sizeof(struct ListNode));
node2 = malloc(sizeof(struct ListNode));
node3 = malloc(sizeof(struct ListNode));
node4 = malloc(sizeof(struct ListNode));
head->data = 1;
head->next = NULL;
node1 = head;
node1->next = node2;
node2->data = 2;
node2->next = node3;
node3->data = 3;
node3->next = node4;
node4->data = 4;
node4->next = newNode;
newNode->data = 5;
newNode->next = NULL;
return head;
}
int PrintFromBeginning(struct ListNode *head)
{
if(!head)
return 0;
else
{
printf("| %d |",head->data);
return PrintFromBeginning(head->next);
}
}
int CheckOddorEvenLength(struct ListNode *head)
{
if(!head)
return 0;
else
{
return (1 + CheckOddorEvenLength(head->next))%2;
}
}
struct ListNode *FindMiddleNode(struct ListNode *head)
{
struct ListNode *ptr1x, *ptr2x;
int i = 0;
ptr1x = ptr2x = head;
while(ptr1x->next)
{
if(i == 0)
{
ptr1x = ptr1x->next;
i = 1;
}
else
{
ptr1x = ptr1x->next;
ptr2x = ptr2x->next;
i = 0;
}
}
return ptr2x;
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
struct ListNode *head = InitLinkedList();
PrintFromBeginning(head);
if(CheckOddorEvenLength(head))
printf("\n-- Odd---");
else
printf("\n--- Even---");
printf("\n---Middle node: %d",FindMiddleNode(head)->data);
return 0;
}
---
Hàm cơ bản trong linked list dùng hàm đệ quy
#include
struct ListNode * InitLinkedList();
int PrintFromBeginning(struct ListNode *head);
int CheckOddorEvenLength(struct ListNode *head);
struct ListNode *FindMiddleNode(struct ListNode *head);
//#define NULL 0
struct ListNode{
int data;
struct ListNode *next;
};
struct ListNode * InitLinkedList()
{
struct ListNode *head = malloc(sizeof(struct ListNode));
struct ListNode *node1, *node2, *node3, *node4;
struct ListNode *newNode = malloc(sizeof(struct ListNode));
node2 = malloc(sizeof(struct ListNode));
node3 = malloc(sizeof(struct ListNode));
node4 = malloc(sizeof(struct ListNode));
head->data = 1;
head->next = NULL;
node1 = head;
node1->next = node2;
node2->data = 2;
node2->next = node3;
node3->data = 3;
node3->next = node4;
node4->data = 4;
node4->next = newNode;
newNode->data = 5;
newNode->next = NULL;
return head;
}
int PrintFromBeginning(struct ListNode *head)
{
if(!head)
return 0;
else
{
printf("| %d |",head->data);
return PrintFromBeginning(head->next);
}
}
int CheckOddorEvenLength(struct ListNode *head)
{
if(!head)
return 0;
else
{
return (1 + CheckOddorEvenLength(head->next))%2;
}
}
struct ListNode *FindMiddleNode(struct ListNode *head)
{
struct ListNode *ptr1x, *ptr2x;
int i = 0;
ptr1x = ptr2x = head;
while(ptr1x->next)
{
if(i == 0)
{
ptr1x = ptr1x->next;
i = 1;
}
else
{
ptr1x = ptr1x->next;
ptr2x = ptr2x->next;
i = 0;
}
}
return ptr2x;
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
struct ListNode *head = InitLinkedList();
PrintFromBeginning(head);
if(CheckOddorEvenLength(head))
printf("\n-- Odd---");
else
printf("\n--- Even---");
printf("\n---Middle node: %d",FindMiddleNode(head)->data);
return 0;
}
---
Hàm cơ bản trong linked list dùng hàm đệ quy
Circular Array
Circular Array = Circular Buffer = Cyclic Buffer = Ring Buffer
The magic behind Circular Array is the operator: Mod
The magic behind Circular Array is the operator: Mod
Embedded System interview Question - Câu hỏi cơ bản thường gặp trong lập trình nhúng
Câu hỏi cơ bản thường gặp trong lập trình nhúng
Static variable in a function only remain one copy of itself.
Static variable in a module can be used by any function in the module
Static function can only be called in its class
2. What are volatile variables?
Volatile variables may change its value unexpectedly in the program.
The program will check its value every time, it tries to use it.
If a variable is not volatile, the program may keep a copy of the var in its cache.
3. What do you mean by const keyword ?
A constant variable is a read only variable. You cant change its value else where except initialization.
4. What is interrupt latency?
Interrupt latency is the time between the generation of interrupt and the time for interrupt handler to process it.
5. How you can optimize it?
We may use polling and message passing for interrupt to handle interrupt immediately.
Scheduling algorithm
This is an implementation of ASAP scheduling algorithm, ALAP scheduling algorithm and LIST_L scheduling algorithm.
It is assumed that:
+ ALU will do the arithmetical operations: +, -, >,<, etc.
+ Multiplier: *
+ Divisor: /
LIST_L scheduling algorithm: (adjusted from the book: Synthesis and Optimizations of Digital Circuits by Giovanni De Micheli)
It is assumed that:
+ ALU will do the arithmetical operations: +, -, >,<, etc.
+ Multiplier: *
+ Divisor: /
LIST_L scheduling algorithm: (adjusted from the book: Synthesis and Optimizations of Digital Circuits by Giovanni De Micheli)
{
Repeat until all vertices
determined {
Determined the distance
label between vertex Vi and sink;
}
Repeat until all non-leaf vertices are scheduled: {
Repeat for each source
type
{
Determine
ready vertices U;
Determine
unfinished vertices T;
Select S Є U;
Schedule
S at clock cycle l;
}
l = l + 1;
}
return (t);
}
[Thuật toán cơ bản] Xác định số nguyên tố
Xác định số nguyên tố: ngôn ngữ C
#include
#include
void main()
{
int i,n,ngt=1;
printf("Nhap so n = "); scanf("%d",n);
for(i=0;i
(ng_to=1)?printf("%d la so nguyen to",i):printf("%d khong la hop so",i);
getch();
}
Lập trình C: Tìm số nguyên tố
Tìm số nguyên tố dùng C
Thuật toán tìm số nguyên tố dùng C
Thuật toán xác định số nguyên tố dùng C
#include
#include
void main()
{
int i,n,ngt=1;
printf("Nhap so n = "); scanf("%d",n);
for(i=0;i
(ng_to=1)?printf("%d la so nguyen to",i):printf("%d khong la hop so",i);
getch();
}
Lập trình C: Tìm số nguyên tố
Tìm số nguyên tố dùng C
Thuật toán tìm số nguyên tố dùng C
Thuật toán xác định số nguyên tố dùng C
[Thuật toán cơ bản] A simple algorithm for getting a square root of a number
Thuật toán tính căn bậc 2 dùng ngôn ngữ C / Lập trình C
#include
#include
#include
void main()
{
double a,xn,c;
printf("\nNhap: ");scanf("%lf",&a);
xn = a;
do
{
c = xn;
xn = (xn*xn + a)/(2*xn);
}while(fabs((xn-c)/c) >= 0.00001);
printf("\ncan bac 2 sai so: %lf",xn);
printf("\nchinh sac: %lf", sqrt(a));
}
Thuật toán tính căn bậc hai dùng ngôn ngữ C / Lập trình C
Lập trình C: Tính căn bậc hai
Ngôn Ngữ C: Tính căn bậc 2
#include
#include
#include
void main()
{
double a,xn,c;
printf("\nNhap: ");scanf("%lf",&a);
xn = a;
do
{
c = xn;
xn = (xn*xn + a)/(2*xn);
}while(fabs((xn-c)/c) >= 0.00001);
printf("\ncan bac 2 sai so: %lf",xn);
printf("\nchinh sac: %lf", sqrt(a));
}
Thuật toán tính căn bậc hai dùng ngôn ngữ C / Lập trình C
Lập trình C: Tính căn bậc hai
Ngôn Ngữ C: Tính căn bậc 2
C programing trick!!
What is wrong ??
#include
#include
void main()
{
printf("%10.0f",-3456);
getch();
}
There might be some tricks on C programming section in an interview test. Have you ever experienced such kind of trick. If not, above is one of a typical examples which might be on your interview test.
Try to figure out what is going on with above short code !!!
At the first glance, you may ask yourself what is wrong with it. It is just a simple code, nothing wrong with it. But, when you actually run this kind of code. the printing result is not as your expected. It's gonna be 0.
What is the problem here? ---> Try to figure it out by yourself ;)
How to fix that code to run in a proper way ?
---> it is so easy, isn't it. Just need to put 3456.0 instead of 3456
#include
#include
void main()
{
printf("%10.0f",-3456);
getch();
}
There might be some tricks on C programming section in an interview test. Have you ever experienced such kind of trick. If not, above is one of a typical examples which might be on your interview test.
Try to figure out what is going on with above short code !!!
At the first glance, you may ask yourself what is wrong with it. It is just a simple code, nothing wrong with it. But, when you actually run this kind of code. the printing result is not as your expected. It's gonna be 0.
What is the problem here? ---> Try to figure it out by yourself ;)
How to fix that code to run in a proper way ?
---> it is so easy, isn't it. Just need to put 3456.0 instead of 3456
Khác nhau cơ bản giữa "nor flash" và "nand flash"
Về cơ bản nhất, thì giữa "nor flash" và "nand flash" có 2 điểm khác nhau lớn là:
- Sự kết nối giữa các cell trong flash.
- Interface hỗ trợ cho việc read/write flash
- NOR flash hỗ trợ việc read/write theo random access.
- NAND flash chỉ cho phép việc truy cập theo page.
------
name: mathhoang
vietnam_hoangminhnguyen@yahoo.com
- Sự kết nối giữa các cell trong flash.
- Interface hỗ trợ cho việc read/write flash
- NOR flash hỗ trợ việc read/write theo random access.
- NAND flash chỉ cho phép việc truy cập theo page.
------
name: mathhoang
vietnam_hoangminhnguyen@yahoo.com
Sự khác nhau giữa "random access" và "sequence access"
Một cách tổng quát, random access là khả năng truy cập vào một vùng nhớ ở 1 vị trí bất kỳ, đối nghịch với random access là sequence access.
Trong sequence access, việc truy cập bắt buộc phải đi theo tuần tự từ điểm A tới điểm Z. Trong khi đó, random access thì việc truy cập có thể đi tới điểm Z từ bất kỳ điểm nào ( có thể là: A, B, F, .... ).
Cả 2 kiểu truy cập ở trên đều có những điểm mạnh riêng. Nếu chúng ta muốn truy cập vào vùng nhớ với thông tin lưu trữ kiểu tuần tự thì sequence access sẽ nhanh hơn. Nếu truy cập vào 1 vị trí bất kỳ trong vùng nhơ thì random access sẽ là chọn lựa tốt hơn.
Đôi khi người ta còn gọi random access là direct access.
------
name: mathhoang
vietnam_hoangminhnguyen@yahoo.com
Trong sequence access, việc truy cập bắt buộc phải đi theo tuần tự từ điểm A tới điểm Z. Trong khi đó, random access thì việc truy cập có thể đi tới điểm Z từ bất kỳ điểm nào ( có thể là: A, B, F, .... ).
Cả 2 kiểu truy cập ở trên đều có những điểm mạnh riêng. Nếu chúng ta muốn truy cập vào vùng nhớ với thông tin lưu trữ kiểu tuần tự thì sequence access sẽ nhanh hơn. Nếu truy cập vào 1 vị trí bất kỳ trong vùng nhơ thì random access sẽ là chọn lựa tốt hơn.
Đôi khi người ta còn gọi random access là direct access.
------
name: mathhoang
vietnam_hoangminhnguyen@yahoo.com
Iterative and Incremental development
I – Giới thiệu
Iterative and Incremental development là phương pháp cốt lõi của tiến trình phát triển phần mềm theo chu kỳ. Iterative and Incremental development được phát triển nhằm bù đắp lại những điểm yếu của phương pháp waterfall model. Phương pháp này thường bắt đầu bằng một kế hoạch khởi tạo ban đầu và kế thúc bằng việc triển khai cùng với những tương tác giữa những chu kỳ.
--- đọc tiếp bên dưới ---
-----
welcome mọi feedback của các pạn ^ ^
================================================
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
site: http://h3dgroup.com
blog: http://kattyflea.co.cc
================================================
Iterative and Incremental development là phương pháp cốt lõi của tiến trình phát triển phần mềm theo chu kỳ. Iterative and Incremental development được phát triển nhằm bù đắp lại những điểm yếu của phương pháp waterfall model. Phương pháp này thường bắt đầu bằng một kế hoạch khởi tạo ban đầu và kế thúc bằng việc triển khai cùng với những tương tác giữa những chu kỳ.
--- đọc tiếp bên dưới ---
-----
welcome mọi feedback của các pạn ^ ^
================================================
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
site: http://h3dgroup.com
blog: http://kattyflea.co.cc
================================================
TimeBoxing là gì ?
timeboxing là một kỹ thuật lập kế hoạch phổ biến trong việc lên kế hoạch cho 1 project( chủ yếu được dùng trong phát triển phần mềm), trong phương pháp này thì schedule được chia thành một số giai đoạn nhỏ ( mỗi giai đoạn được gọi là một timebox, thông thường thời gian cho các giai đoạn này là tư 1 tuần tới 6 tuần), mỗi giai đoạn sẽ phải có deliverable, deadline và budget cho nó.
- trong RAD( rapid application development ) thì timebox được xem như là thành phần cốt lõi để lên kế hoạch phát triển phần mềm.
- timebox được sử dụng như là hình thức quản lý rủ ro, đặc biệt là những công việc mà có khả năng mở rộng hoặc kéo dài thời gian deadline => thời gian deadline trong việc nên kế hoạch ko nên thay đổi bởi vì nó sẽ ảnh hướng tới ngày delivery sản phẩm.
- khi một deadline mà bị trễ thì những giải pháp sau có thể được áp dụng
---------- bỏ đi những requirement mà ảnh hưởng ít tới project
---------- làm việc OT để bù lại khoảng thời gian đã mất
---------- di dời deadline
================================================
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
mail: hoang.nguyen@h3dgroup.com
site: http://h3dgroup.com
blog: http://kattyflea.co.cc
================================================
- trong RAD( rapid application development ) thì timebox được xem như là thành phần cốt lõi để lên kế hoạch phát triển phần mềm.
- timebox được sử dụng như là hình thức quản lý rủ ro, đặc biệt là những công việc mà có khả năng mở rộng hoặc kéo dài thời gian deadline => thời gian deadline trong việc nên kế hoạch ko nên thay đổi bởi vì nó sẽ ảnh hướng tới ngày delivery sản phẩm.
- khi một deadline mà bị trễ thì những giải pháp sau có thể được áp dụng
---------- bỏ đi những requirement mà ảnh hưởng ít tới project
---------- làm việc OT để bù lại khoảng thời gian đã mất
---------- di dời deadline
================================================
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
mail: hoang.nguyen@h3dgroup.com
site: http://h3dgroup.com
blog: http://kattyflea.co.cc
================================================
Sliding Window Protocols
Sliding Window Protocols are a feature of packet-based data transmission protocols. They are used where reliable in-order delivery of packets is required, such as in the data link layer (OSI model) as well as in TCP (transport layer of the OSI model).
Conceptually, each portion of the transmission (packets in most data link layers, but bytes in TCP) is assigned a unique consecutive sequence number, and the receiver uses the numbers to place received packets in the correct order, discarding duplicate packets and identifying missing ones. The problem with this is that there is no limit of the size of the sequence numbers that can be required.
By placing limits on the number of packets that can be transmitted or received at any given time, a sliding window protocol allows an unlimited number of packets to be communicated using fixed-size sequence numbers.
---
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
mail: vietnam_hoangminhnguyen@Yahoo.com
site: http://kattyflea.co.cc
---
Conceptually, each portion of the transmission (packets in most data link layers, but bytes in TCP) is assigned a unique consecutive sequence number, and the receiver uses the numbers to place received packets in the correct order, discarding duplicate packets and identifying missing ones. The problem with this is that there is no limit of the size of the sequence numbers that can be required.
By placing limits on the number of packets that can be transmitted or received at any given time, a sliding window protocol allows an unlimited number of packets to be communicated using fixed-size sequence numbers.
---
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
mail: vietnam_hoangminhnguyen@Yahoo.com
site: http://kattyflea.co.cc
---
Reliability Terminology
Sometimes My friends ask me to differ some definitions: System failure, System error, System fault and Human error. actually, these definitions lead me some confusion while distinguishing between them.
After spending a little time to investigate these definitions, now I can distinguish them:
System failure
An event that occurs at some point in time when the system does not deliver a service as expected by its users
System error
An erroneous system state that can lead to system behaviour that is unexpected by system users.
System fault
A characteristic of a software system that can lead to a system error. For example, failure to initialise a variable could lead to that variable having the wrong value when it is used.
Human error or mistake
Human behaviour that results in the introduction of faults into a system.
---
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
mail: vietnam_hoangminhnguyen@Yahoo.com
---
After spending a little time to investigate these definitions, now I can distinguish them:
System failure
An event that occurs at some point in time when the system does not deliver a service as expected by its users
System error
An erroneous system state that can lead to system behaviour that is unexpected by system users.
System fault
A characteristic of a software system that can lead to a system error. For example, failure to initialise a variable could lead to that variable having the wrong value when it is used.
Human error or mistake
Human behaviour that results in the introduction of faults into a system.
---
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
mail: vietnam_hoangminhnguyen@Yahoo.com
---
What is CASE (Computer-Aided Software Engineering)
Software systems that are intended to provide automated support for software process activities.
CASE systems are often used for method support.
Upper-CASE
Tools to support the early process activities of requirements and design;
Lower-CASE
Tools to support later activities such as programming, debugging and testing.
---
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
mail: vietnam_hoangminhnguyen@Yahoo.com
---
CASE systems are often used for method support.
Upper-CASE
Tools to support the early process activities of requirements and design;
Lower-CASE
Tools to support later activities such as programming, debugging and testing.
---
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
mail: vietnam_hoangminhnguyen@Yahoo.com
---
Subscribe to:
Posts (Atom)