Le support aux utilisateurs et les demandes de création de comptes externes doivent être faites depuis les issues du projet GitLab HEFR (https://gitlab.forge.hefr.ch/forge-hefr/gitlab-hefr)

Commit d487be4d authored by Simon Braillard's avatar Simon Braillard
Browse files

First commit

parents
/dist/
/out/
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/tp-algorithmique.iml" filepath="$PROJECT_DIR$/tp-algorithmique.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="TP_Algo" default="default" basedir=".">
<description>Builds, tests, and runs the project TP_Algo.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="TP_Algo-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
This diff is collapsed.
build.xml.data.CRC32=50191940
build.xml.script.CRC32=f7b31728
build.xml.stylesheet.CRC32=f85dc8f2@1.96.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=50191940
nbproject/build-impl.xml.script.CRC32=188bdd42
nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.96.0.48
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/TP_Algo.jar
dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/TP_Algo
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=11
javac.target=11
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.html5=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
# The jlink additional root modules to resolve
jlink.additionalmodules=
# The jlink additional command line parameters
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=TP_Algo
main.class=s04.Sorting
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>TP_Algo</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
package s01;
public class CharStack {
private int topIndex;
private char[] buffer;
private static final int DEFAULT_SIZE = 10;
// Default constructor using the default size for the buffer
public CharStack() {
this(DEFAULT_SIZE);
}
// Constructor with buffer size in parameter
public CharStack(int estimatedSize) {
buffer = new char[estimatedSize];
topIndex = -1;
}
// Check if the stack is empty
public boolean isEmpty() {
boolean isEmpty = false;
if (buffer[0] == 0) {
isEmpty = true;
}
return isEmpty;
}
// Get the top char of the stack
public char top() {
return buffer[topIndex];
}
// Remove the top char of the stack
public char pop() {
char top = 0;
if (!isEmpty()) {
top = buffer[topIndex];
}
buffer[topIndex] = 0;
topIndex -= 1;
return top;
}
// Add a char at the top of the stack
public void push(char x) {
if ((topIndex + 1) >= buffer.length) {
char[] newBuffer = new char[buffer.length * 2];
for (int i = 0; i < buffer.length; i++) {
newBuffer[i] = buffer[i];
}
buffer = newBuffer;
}
buffer[topIndex + 1] = x;
topIndex += 1;
}
// Getters only used for testing
public char[] getBuffer() {
return buffer;
}
public int getTopIndex() {
return topIndex;
}
}
package s01;
public class CharStackTest {
public static void main(String[] args) {
// Creating the stack with a size of 3
CharStack charStack = new CharStack(3);
showCharStackInfo(charStack);
// Pushing 3 chars in the buffer
charStack.push('a');
charStack.push('b');
charStack.push('c');
showCharStackInfo(charStack);
// Pushing one more char to check if the size of the buffer is 2x bigger
charStack.push('d');
showCharStackInfo(charStack);
// Removing a char
charStack.pop();
showCharStackInfo(charStack);
// Removing all chars
charStack.pop();
charStack.pop();
charStack.pop();
showCharStackInfo(charStack);
}
// Show all the information needed to check that the stack is working properly
public static void showCharStackInfo(CharStack charStack) {
System.out.println("--------------------");
System.out.println("TopIndex: " + charStack.getTopIndex());
System.out.println("IsEmpty: " + charStack.isEmpty());
System.out.println("BufferLength: " + charStack.getBuffer().length);
System.out.print("BufferContent: ");
for (int i = 0; i <= charStack.getTopIndex(); i++) {
System.out.print(charStack.getBuffer()[i] + " ");
}
System.out.println();
System.out.println("--------------------");
}
}
package s01;
public class Parenth {
//-------------------------------------
// Usage: java Parenth 'aa(({adf}))' don't forget the ' !
//-------------------------------------
public static void main(String[] args) {
if (args.length != 0) {
String s = args[0];
System.out.println(s + " : " + isBalanced(s));
}
String[] t = {"((o{()oo})o)",
"oo((((((((((((((((((((o))))))))))))))))))))o{}",
"oo())(()",
"oo()((())()",
"oo()((()})",
")()",
"((}))"
};
boolean[] answer = {true, true, false, false, false, false, false};
boolean ok = true;
for (int i = 0; i < t.length; i++) {
ok = ok & (isBalanced(t[i]) == answer[i]);
System.out.print(t[i] + " : " + isBalanced(t[i]));
System.out.println(" (should be " + answer[i] + ")");
}
if (ok) System.out.println("\nTest passed successfully");
else System.out.println("\nOups... There's a bug !");
}
//-------------------------------------
public static boolean isBalanced(String l) {
char c;
CharStack s = new CharStack();
for (int i = 0; i < l.length(); i++) {
c = l.charAt(i);
if (isOpeningParenth(c)) {
s.push(c);
} else if (isClosingParenth(c)) {
if (!s.isEmpty()) {
if (isMatchingParenth(s.top(), c)) {
s.pop();
} else {
break;
}
} else if (isClosingParenth(c)) {
return false;
}
}
}
return s.isEmpty();
}
//-------------------------------------
private static boolean isOpeningParenth(char c) {
return (c == '(') || (c == '{');
}
private static boolean isClosingParenth(char c) {
return (c == ')') || (c == '}');
}
private static boolean isMatchingParenth(char c1, char c2) {
return ((c1 == '(') && (c2 == ')'))
|| ((c1 == '{') && (c2 == '}'));
}
}
package s03;
public class AmStramGram {
public static void main(String[] args) {
int n = 420, k = 25;
if (args.length == 2) {
n = Integer.parseInt(args[0]);
k = Integer.parseInt(args[1]);
}
System.out.println("Winner is " + winnerAmStramGram(n, k));
}
public static int winnerAmStramGram(int n, int k) {
List l = new List();
ListItr li = new ListItr(l);
int i;
// Add 1 to n into the list
while (n > 0) {
li.insertAfter(n--);
}
while (l.size > 1) {
// Iterate to k
for (i = 1; i < k; ++i) {
li.goToNext();
if (li.isLast()) {
li.goToFirst();
}
}
li.removeAfter();
// If remove was the last, go to the first element
if (li.isLast()) {
li.goToFirst();
}
}
return li.consultAfter();
}
}
package s03;
public class List {
public ListNode first, last;
public int size;
public List() {
size = 0;
}
public boolean isEmpty() {
return size() == 0;
}
public int size() {
return size;
}
// ==================================================
// === Small Test Program ===
// ==================================================
public static void main(String[] args) {
if (findsBugInScenario1())
System.out.println("Something is wrong...");
else
System.out.println("Test passed successfully");
}
// --------------------
private static boolean findsBugInScenario1() {
int[] t = {10, 20, 30, 40, 50};
List l = new List();
ListItr li = new ListItr(l);
if (!l.isEmpty()) return true;
if (!li.isFirst()) return true;
if (!li.isLast()) return true;
li.insertAfter(30);
li.insertAfter(10);
li.goToNext();
li.insertAfter(20);
li.goToLast();
li.insertAfter(50);
li.insertAfter(40);
li.goToFirst();
for (int i = 0; i < t.length; i++) {
if (li.consultAfter() != t[i]) return true;
li.goToNext();
}
if (!li.isLast()) return true;
li.goToFirst();
li.removeAfter();
li.goToNext();
li.removeAfter();
li.goToNext();
li.removeAfter();
li.goToFirst();
if (li.consultAfter() != 20) return true;
li.goToNext();
if (li.consultAfter() != 40) return true;
li.goToNext();
if (!li.isLast()) return true;
return false;
}
// --------------------
}
package s03;
public class ListItr {
public final List list;
public ListNode pred, succ;
// ----------------------------------------------------------
public ListItr(List anyList) {
list = anyList;
goToFirst();
}
// ----------------------------------------------------------
public void insertAfter(int e) {
// Creating the new list node
ListNode newListNode = new ListNode(e, succ, null);
// Setting the next node as the successor to the new list node
newListNode.next = succ;
// Incrementing list size
list.size++;
// When there is already a node in the list
if (succ != null) {
// When listItr is on the far left
if (pred == null) {
succ.prev = newListNode;
newListNode.next = succ;
newListNode.prev = null;
list.first = newListNode;
// When listItr is between 2 nodes
} else {
pred.next = newListNode;
succ.prev = newListNode;
newListNode.next = succ;
newListNode.prev = pred;
}
// When listItr is on the far right
} else if (pred != null) {
newListNode.prev = pred;
pred.next = newListNode;
list.last = newListNode;
// When there is no node in the list
} else {
list.last = newListNode;
list.first = newListNode;
}
// Setting the new node as the successor
succ = newListNode;
}
// ----------------------------------------------------------
public void removeAfter() {
// Decrementing the list size
list.size--;
// When there is already a node in the list
if (succ != null) {
// When listItr is on the far left
if (pred == null) {
succ = succ.next;
if (succ != null) {
succ.prev = null;
}
list.first = succ;
// When listItr is between the two last nodes
} else if (succ.next == null) {
succ = null;
pred.next = null;
list.last = pred;
// When listItr is between 2 nodes
} else {
succ = succ.next;
succ.prev = pred;
pred.next = succ;
}
}
}
// ----------------------------------------------------------
public int consultAfter() {
return succ.elt;
}
public void goToNext() {