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; }
Insert Node into the end of list
[Easy Data Structure] Nice functions to traverse and find middle node in Singly Linked List
#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
[Python] Inheritance
By looking at below example, it is easy to learn how a class inherits from other classes and how a class is declared, defined and used in Python.
--------------------------------
Python là một ngôn ngữ lập trình hướng đối tượng! bên dưới là một ví dụ đơn giản về tính thừa kế trong Python.
[Python] Small Python program applying Skeleton
This program is just the simplest calculator in the world. The purpose is just to prove how efficient to apply the skeleton into your project. It makes the project have a good look and well-organized.
--------------------
Chương trình máy tính python đơn giản. Cách áp dụng coding style ở bài trước
--------------------
[Python] Skeleton
----------
Bộ khung mẫu của một chương trình trong python! Nó sẽ giúp ích trong việc tổ chức code
----------
import sys def main(): func1() func2() pass def func1(): # doing your work pass def func2(): # doing your work pass if __name__ == '__main__': sys.exit(main())
Boring C code ever! - Easy to get error
Ngoài ra, nếu trước đó ta đã khai báo một biến, sau đó lại define một tên trùng với tên biến đó. Thì từ lúc define đó trở đi, tên được define sẽ được sử dụng cho tới khi ta undef nó ( như ví dụ với M bên dưới)
#include
#define in printf
#define N 100
#define length1 3 + 5
#define length2 (3+5)
void main()
{
int M = 200;
int x = 2*length1;
int y = 2*length2;
in("\n N= %d M=%d",N,M);
#define M 300
in("\nM=%d",M);
#undef M
in("\nM=%d",M);
in("\n%d",x);
in("\n%d",y);
}
[Thuật toán cơ bản] Xác định số nguyên tố
#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
#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
Boring C code ever! - solve quadratic equations
Doing all of the calculation in only 1 code line for solving quadratic equation
How boring it is, isn't it :D
#include
#include
#include
void main()
{
double a,b,c;
printf("=======================================\n=============== GPTB 2 ================\n=======================================\nNhap du lieu a,b,c cua phuong ax^2 + bx + c = 0\n");
printf("Nhap a = "); scanf("Nhap a = %lf",&a);
printf("\n");
printf("Nhap b = "); scanf("%lf",&b);
printf("\n");
printf("Nhap c = "); scanf("%lf",&c);
printf("\n");
(a == 0)?((c==0)?((b == 0)?printf("PT vo so nghiem\n"):printf("PT vo nghiem")):((b == 0)?printf("PT vo nghiem\n"): printf("PT co 1 nghiem: %lf",-c/b))):((c != 0) ? ((b == 0) ?(( c< 0) ?printf("PT co nghiem: x = +/-%lf",sqrt(-c/a)):printf("PT vo nghiem\n")):(((b*b - 4*a*c) > 0) ?printf("PT co 2 nghiem: \nx1 = %lf \nx2 = %lf\n",(-b + sqrt(b*b - 4*a*c))/(2*a),(-b-sqrt(b*b - 4*a*c))/(2*a)):printf("PT vo nghiem\n"))):((b == 0)?printf("PT co nghiem x=0"):printf("PT co 2 nghiem x1 = 0 and x2 = %lf",-b/a)));
}
C programing trick!!
#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
Linked list cơ bản dùng C++
#include
|
Linked list cơ bản sử dụng C++.
Output:
M a t h H o a n g
|
--
Mathhoang
vietnam_hoangminhnguyen
[Java] [Exer5] Bài toán vui tính số năm sẽ về hưu
/**
* cusomized by: mathhoang
* Y!M: vietnam_hoangminhnguyen@yahoo.com
* addr: http://mathhoang.blogspot.com
* subject: java tutorials source code
*/
package Exercise4;
import java.util.*;
public class Example4 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("How much do you want to receive after retiring");
double goal = in.nextDouble();
System.out.println("How much do you put into your account every year");
double payment = in.nextDouble();
System.out.println("Interest in the bank every year");
double interest = in.nextDouble();
double balance = 0;
int years = 0;
while (balance < goal) {
balance += payment;
double intr = balance * interest/100;
balance += intr;
years++;
}
System.out.println("You can retire after: " + years + " years");
}
}
---
name: nguyen minh hoang
Y!M : vietnam_hoangminhnguyen@yahoo.com
net name: mathhoang
[Java] [Exer4] tính lãi xuất ngân hàng
/**
* cusomized by: mathhoang
* Y!M: vietnam_hoangminhnguyen@yahoo.com
* addr: http://mathhoang.blogspot.com
* subject: java tutorials source code
*/
package Exercise3;
public class Exer3 {
private static final int START_RATE = 10;
private static final int NRATES = 6;
private static final int NYEARS = 10;
public static void main(String[] argv) {
double[] interestRate = new double[NRATES];
for (int i = 0; i < interestRate.length; i++) {
interestRate[i] = (START_RATE + i)/ 100.0;
}
double[][] balances = new double[NYEARS][NRATES];
// set initial balances to 10000
for (int i = 0; i < balances[0].length; i++) {
balances[0][i] = 10000;
}
// compue interest for future years
for (int i = 1; i < balances.length; i++){
for (int j = 0; j < balances[i].length; j++){
double oldBalance = balances[i - 1][j];
double interest = oldBalance * interestRate[j];
balances[i][j] = oldBalance + interest;
}
}
// print one row of interest rates
for (int i = 0; i < interestRate.length; i++){
System.out.printf("%9.0f%%", 100 * interestRate[i]);
}
System.out.println();
// print balance table
for (double[] row: balances) {
for (double b: row){
System.out.printf("%10.2f", b);
}
System.out.println();
}
}
}
---
name: nguyen minh hoang
Y!M : vietnam_hoangminhnguyen@yahoo.com
net name: mathhoang
[Java] [Exer3] Chương trình xem ảnh đơn giản
/*
* cusomized by: mathhoang
* Y!M: vietnam_hoangminhnguyen@yahoo.com
* addr: http://mathhoang.blogspot.com
*
*/
package ImageViewer;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class MyFile {
public static void main(String[] args) {
JFrame myFirstGUI = new MyFirstGUI();
myFirstGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFirstGUI.setVisible(true);
}
}
class MyFirstGUI extends JFrame
{
private static final int GUI_HEIGHT = 300;
private static final int GUI_WIDTH = 400;
private JLabel label;
private JFileChooser chooser;
public MyFirstGUI(){
setTitle("This is my first Java GUI Application");
setBackground(Color.blue);
setDefaultLookAndFeelDecorated(false);
setSize(GUI_HEIGHT, GUI_WIDTH);
// set up components
label = new JLabel();
add(label);
chooser = new JFileChooser(new File("."));
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menuItem = new JMenu("File");
menuBar.add(menuItem);
JMenuItem openItem = new JMenuItem("Open");
menuItem.add(openItem);
openItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION){
String path = chooser.getSelectedFile().getPath();
label.setIcon(new ImageIcon(path));
}
}
});
JMenuItem exitItem = new JMenuItem("Exit");
menuItem.add(exitItem);
exitItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
});
}
}
---
name: nguyen minh hoang
Y!M : vietnam_hoangminhnguyen@yahoo.com
net name: mathhoang
small java projects for begginer
Introduction
Here are over 241 ideas for student projects most likely involving Java. Some ideas might be done by teams or a whole class. Some may develop into commercial projects. You are free to take these ideas and use them as you wish. I would appreciate hearing from you if you decide to implement any of these ideas. I would also like to hear any comments you would like me to add to the descriptions, or ideas you have for projects. If you have such project ideas on your own website, I would be happy to build links here.I have discussed most of the projects many times at length over the last decades on BIX which retained all postings in archives.
Pretty well everything I have to say about each project is spelled out here. I don’t have extra material to give you, unless I explicitly mention it. I don’t have the time to lead you by the hand through a project. If one project is too difficult to tackle at your current level of skill, pick a simpler one.
If you are unemployed, or just out of school, you might hone your skills by tackling some of these projects. They are more like the real world problems you will be given in the workplace. In the real world you have to write the specifications too. They are not handed to you on a plate the way they are in school. I give you many hints on how to solve the problems, far more than you would get in the workplace. These problems are intermediate in degree of hand-holding between school and the workplace.
I would be happy to implement any of these projects for you, for a fee, though I do not do homework.
Which Project to Pick?
People often write me and ask “Which project should I pick?” as if I knew their hearts and abilities. Here is a strategy. First narrow down the choices to the ones that look about your level of difficulty. Then narrow down the ones to your interest in financial potential. Then narrow down projects to ones that involve servers or do not. Now weed out ones that look boring or esoteric to you. Now look for the project with most heart. Do you care about the result? You will need to care in the times ahead when the hard work comes of implementing, documenting, researching, and futzing about to get it to work. For children, video games are the usual choice. For adults, it can be anything. Further, you don’t have to pick one of my projects. Let one of mine inspire you to create one your own. Think in terms of your own interests and hobbies. What would be useful? Think about the frustrations you have had with software. What sort of better mousetrap does the world need?Learning More
In my email inbasket each day are two or three requests for more information about one or more of these student projects. I don’t have any materials other than what I have provided here unless I explicity mentioned that I did. Most often these requests come from students in third world countries, but sometimes they come from commercial developers.Students imagine I have complete detailed specs written on every class. The key skill students must learn is writing the spec, and doing the overall design of a decently large project. Any boob can code given a detailed class specification. In the real world you are never handed tidy perfectly-specified little problems than can be handled with two or three pages of code. In the real world, you won’t even get project outlines anywhere near as detailed as I have given you here. They will never contain any implementation hints as my outlines do. You have to pull teeth to get even the vaguest information about what the program should do. You have to write prototype systems. Only then are your users smart enough to tell you what they really wanted, or are you smart enough to suggest to them possible options they might enjoy.
My advice for a student who thinks a project is too difficult, is to create a sub project that he thinks he might tackle successfully, or try a simpler different project entirely. After that experience, he can add a bit more complexity. Trying to solve the problem all at once just leads to overwhelm. Don’t feel embarrassed that the sub project would have no practical use. It is just a stepping stone.
Though I have no additional materials to send you, I am willing to answer specific questions about the projects. I will normally add that material into the project descriptions for others too.
For team projects underway you can join Asynchrony, Enhydra or SourceForge.
Perry Mason was a whodunnit popular in the 1950s. If it is ever revived we will need a writers guide to make sure the new episodes conform to the stock formula:~ Roedy (born: 1948-02-04 age: 63)
- Any person behaving rudely or smugly in the first 10 minutes of the episode will be murdered.
- Anyone Perry represents is innocent.
- Lt. Tragg and Hamilton Burger must treat Perry as a likely criminal, even though they have known him for years.
- Young good-looking couples in love are never guilty.
- Anyone who says “I swear I didn’t do it” in a loud voice is always innocent.
- Any guilty party will instantly confess as soon as Perry conjectures how they committed the crime (not necessarily a murder), even if Perry has similarly falsely accused half a dozen people prior.
- At the end of each episode, Perry Mason, Della Street and Paul Drake must be alive, single and unencumbered with a partner.
- Every show must end with a lame joke and group laughter.
==> this's my own takenote for this site !!! http://www.1000projects.com/new/java/mini/13.html |