|
|
Dangling pointers in computer programming are pointers that do not point to a valid object of the appropriate type. These are special cases of memory safety violations.
Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. As the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data.
|
|
|
|
|
I'm getting an incorrect output and getting some duplicates. i have traced through it several times both by myself and with my teacher but we can't find the mistake. Any help or guidance would be very much appreciated!!
This is my output:
BRUTE FORCE HULL
(45.49727, 99.40442)
(53.715485, 98.34267)
(45.49727, 99.40442)
(-90.16175, 96.802765)
(-97.703, 79.97963)
(-90.16175, 96.802765)
(91.41145, 88.82591)
(96.42737, 80.445724)
(91.41145, 88.82591)
(53.715485, 98.34267)
(96.42737, 80.445724)
(99.23712, 0.083602905)
(99.23712, 0.083602905)
(99.61636, -74.81982)
(82.97812, -94.3812)
(98.21695, -80.666794)
This is what the output should be"
BRUTE FORCE HULL
(45.49727, 99.40442)
(53.715485, 98.34267)
(91.41145, 88.82591)
(96.42737, 80.445724)
(99.23712, 0.083602905)
(99.61636, -74.81982)
(98.21695, -80.666794)
(82.97812, -94.3812)
(63.255356, -96.624664)
(-80.099915, -88.48059)
(-92.14374, -81.84515)
(-97.703, 79.97963)
(-90.16175, 96.802765)
public class HullTest {
ArrayList<Point> pointList = new ArrayList<Point>();
@SuppressWarnings("unused")
private int numPoints = -1;
public void readFile(String points) throws FileNotFoundException
{
Scanner sc = new Scanner(new File(points));
numPoints = sc.nextInt();
while (sc.hasNextFloat())
{
float x = sc.nextFloat();
float y = sc.nextFloat();
Point point = new Point(x,y);
addPoint(point);
}
sc.close();
}
public void addPoint(Point point)
{
pointList.add(point);
}
public ArrayList<Line> BruteForce()
{
ArrayList<Line> solutionPointsList = new ArrayList<Line>();
for (int i = 0; i < pointList.size()-1; i++)
{
for (int j = i+1; j < pointList.size(); j ++)
{
boolean isSolutionLine = true;
int initialSign = 0;
Point pointA = pointList.get(i);
Point pointB = pointList.get(j);
float A = pointB.getY() - pointA.getY();
float B = pointA.getX() - pointB.getX();
float C = pointA.getX()*pointB.getY() - pointA.getY()*pointB.getX();
for (int x = 0; x < pointList.size(); x++)
{
Point pointC = pointList.get(x);
float pointRegion = A*pointC.getX() + B*pointC.getY() - C;
if (initialSign != 0)
{
if (pointRegion > 0 && initialSign < 0)
{
isSolutionLine = false;
break;
} else if (pointRegion < 0 && initialSign > 0)
{
isSolutionLine = false;
break;
}
} else
{
if (pointRegion > 0)
initialSign = 1;
else if (pointRegion < 0)
initialSign = -1;
}
}
if(isSolutionLine)
{
Line temp = new Line(pointA,pointB);
solutionPointsList.add(temp);
}
}
}
return solutionPointsList;
}
public void PrintSolution ()
{
ArrayList<Line> list = BruteForce();
System.out.println("BRUTE FORCE HULL");
for (int i = 0; i < list.size(); i ++)
{
System.out.println( "(" + list.get(i).getPointA().getX() + ", " + list.get(i).getPointA().getY() + ")");
System.out.println( "(" + list.get(i).getPointB().getX() + ", " + list.get(i).getPointB().getY() + ")");
}
}
public static void main (String args[])
{
HullTest hull = new HullTest();
try {
hull.readFile(args[0]);
} catch (FileNotFoundException e) {
System.out.println("File not found!");
}
hull.PrintSolution();
}
}
I also have the input file if needed.
|
|
|
|
|
I dont know what you did exactly, as I dont know Java that well. In VB I have been using the following code:
Public Function ConvexHull2D(ByVal points As PointCollection) As PointCollection
Dim SortedList As New PointCollection
Dim Upper As New PointCollection
Dim Lower As New PointCollection
Dim tempPoints As New PointCollection
For Each p As Point In points
If Not tempPoints.Contains(p) Then tempPoints.Add(p)
Next
Dim res As New PointCollection
SortedList = SortPoints(tempPoints, True)
Upper = SortedList
For i As Integer = SortedList.Count - 1 To 0 Step -1
Lower.Add(SortedList(i))
Next
Dim j_set As Boolean = False
Dim j As Integer = 0
Dim r As Integer
Do While j < Upper.Count - 2
r = WhichSide(Upper(j + 1), Upper(j), Upper(j + 2))
If r = -1 Or r = 0 Then
Upper.RemoveAt(j + 1)
j = 0
j_set = True
End If
If Not j_set Then
j += 1
End If
j_set = False
Loop
j = 0
j_set = False
Do While j < Lower.Count - 2
r = WhichSide(Lower(j + 1), Lower(j), Lower(j + 2))
If r = -1 Or r = 0 Then
Lower.RemoveAt(j + 1)
j = 0
j_set = True
End If
If Not j_set Then
j += 1
End If
j_set = False
Loop
For Each p As Point In Upper
res.Add(p)
Next
For Each p As Point In Lower
If Not res.Contains(p) Then
res.Add(p)
End If
Next
Return res
End Function
Private Function WhichSide(ByVal PointToBeEvaluated As Point, ByVal StartPointOnLine As Point, ByVal EndPointOnLine As Point) As Integer
Dim ReturnvalueEquation As Double
ReturnvalueEquation = ((PointToBeEvaluated.Y - StartPointOnLine.Y) _
* (EndPointOnLine.X - StartPointOnLine.X)) - ((EndPointOnLine.Y - StartPointOnLine.Y) _
* (PointToBeEvaluated.X - StartPointOnLine.X))
If ReturnvalueEquation > 0 Then
Return -1
ElseIf ReturnvalueEquation = 0 Then
Return 0
Else
Return 1
End If
End Function
Public Function SortPoints(ByVal samplepoints As PointCollection, ByVal SortByXdirection As Boolean) As PointCollection
Dim copySamplePoints As Point() = New Point(samplepoints.Count - 1) {}
samplepoints.CopyTo(copySamplePoints, 0)
If SortByXdirection Then
Array.Sort(copySamplePoints, New PointSort(PointSort.Mode.X))
Else
Array.Sort(copySamplePoints, New PointSort(PointSort.Mode.Y))
End If
Dim result As New PointCollection
For Each p As Point In copySamplePoints
result.Add(p)
Next
Return result
End Function
Private Class PointSort
Implements IComparer
Public Enum Mode
X
Y
End Enum
Private currentMode As Mode = Mode.X
Public Sub New(ByVal mode As Mode)
currentMode = mode
End Sub
Private Function IComparer_Compare(ByVal a As Object, ByVal b As Object) As Integer Implements IComparer.Compare
Dim point1 As Point = CType(a, Point)
Dim point2 As Point = CType(b, Point)
If currentMode = Mode.X Then
If point1.X > point2.X Then
Return 1
ElseIf point1.X < point2.X Then
Return -1
Else
If point1.Y > point2.Y Then
Return 1
ElseIf point1.Y < point2.Y Then
Return -1
Else
Return 0
End If
End If
Else
If point1.Y > point2.Y Then
Return 1
ElseIf point1.Y < point2.Y Then
Return -1
Else
If point1.X > point2.X Then
Return 1
ElseIf point1.X < point2.X Then
Return -1
Else
Return 0
End If
End If
End If
End Function
End Class
Code is in VB, but should be easy to transform for you, and it should be n*log n fast, which is optimal although I'll bet there is a lot of possible improvments that could be made.
|
|
|
|
|
we have to compress the bitmap using byte aligned bitmap code can anyone please show some example?? Is there any package for this compression technique in java??
|
|
|
|
|
|
can any one contact me for help , i have a problem with the k-means algorithme implementation with java
have any one an idea to imlement this tabel or arrayliste , the centers and the distance are calculate previously, i would have a list of the class and the element belongds !!!! plz I would be grateful
this is my address : sahnoun.mabrouk@gmail.com
and this is my facebook account : <a href="https://www.facebook.com/sahnoun.mabrouk.52?ref=tn_tnmn"></a>
<pre> grain 27 grain 51 grain 52
27 0.00 0.65 0.68
51 0.65 0.00 0.03
52 0.68 0.03 0.00
33 0.16 0.49 0.51
45 0.49 0.16 0.19
22 0.14 0.78 0.81
28 0.03 0.62 0.65
44 0.46 0.19 0.22
40 0.35 0.30 0.32
38 0.30 0.35 0.38
20 0.19 0.84 0.80
57 0.81 0.16 0.14
</pre>
|
|
|
|
|
If you have a question then post it here with full details. No one is going to start a private consultancy session with you.
|
|
|
|
|
can open notepad.exe file
Launch the executable
function LaunchApp() {
if (!document.all) {
alert ("Available only with Internet Explorer1.");
return;
}
var ws = new ActiveXObject("WScript.Shell");
ws.Exec("C:\Windows\notepad.exe");
}
|
|
|
|
|
And what's your question? And whom do you expect to still use Internet Explorer 1 ?
|
|
|
|
|
Apart from the fact that you've not actually posted a question, this is JavaScript[^], not Java. Despite the similar names, these are two completely different technologies.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hi,
in jsp i will create one button.now if i click on that button .exe file has to execute please can any one help on this.
advance thanks
|
|
|
|
|
How about this:
Runtime rt=Runtime.getRuntime();
String cmd[]={"cmd.exe", "/C", "c:\\WHAT\\EVER\\APPLICATION\\YOU\\WANT\\TO\\START.exe"};
rt.exec(cmd);
|
|
|
|
|
thanks Torsten!!
its working very well and one more query if v have to run .sh file in linux how v can do.
plz can u help me on this
|
|
|
|
|
It's surprisingly pretty much the same:
Runtime rt=Runtime.getRuntime();
String cmd[]={"ls -l"};
rt.exec(cmd);
You can run (kind of) any command you want.
Please take a look at the Description:
Java.lang.Runtime[^] @ docs.oracle.com
regards Torsten
I never finish anyth...
|
|
|
|
|
how to implement multiple languages and multiple themes in spring mvc
|
|
|
|
|
First I want to ask if this the right place for a very beginner.
I can write a program that displays a paragraph, and I can write a program that asks a question and you can fill in the answer. Now I need to have the answer go in the paragraph. Any ideas on what I need to look up in order to do that.
Thanks
|
|
|
|
|
I'm not sure what you mean by "have the answer go in the paragraph", but I would assume some sort of text manipulation. Your best bet would be to go to http://docs.oracle.com/javase/tutorial/java/index.html[^] and work through the tutorials, especially the section on Strings.
|
|
|
|
|
I am new to Java & J2EE , i want to start learning the language from a secure coding point of view .. Please help me with this here..
Is the implementation correct .. will this style of coding be sufficient to prevent SQL injection attacks ?
SQLQuery q = session.createSQLQuery("update tbl_files set orderLevel = orderLevel - 1 where meeting_id="+tbl File.get Tbl Meeting().getId() + " AND order Level>"+ tbl File.getOrder());
q.executeUpdate();
Thanks in advance
|
|
|
|
|
|
Thanks for the quick reply ..
|
|
|
|
|
Hi,
I have the following situation:
- read .XML files
- extract some info
- write the extracted info in .XML file
- display the .XML content in .html and create charts/bar
For the first 3 steps, I used DOM to parse the .XML file and to write info.
What do you suggest for charts/bar?
Thanks
|
|
|
|
|
|
Do you have experience with barchart java?
Somebody recommended SVG --what do you know about it?
Thanks!
|
|
|
|
|
Anca Zara wrote: Do you have experience with barchart java? Sorry, no; you will have to do your own reading.
|
|
|
|