Search Results

Search found 1552 results on 63 pages for 'homework'.

Page 16/63 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • Eclipse says I don't implement Enumeration, but I do

    - by Harm De Weirdt
    Goodmorning everybody, I'm having a little problem with a project for school. We are told to make an Iterator that implements Enumeration over a Hashmap. So i made this Enumeration: public Enumeration<Object> getEnumeration() { return new Enumeration<Object>() { private int itemsDone = 0; Collection<Long> keysCollection = getContent().keySet(); Long [] keys = keysCollection.toArray(new Long[keysCollection.size()]); @Override public boolean hasMoreElements() { if(itemsDone < getContent().size() +1 ) { return true; }else { return false; } } @Override public Object nextElement() { return getContent().get(keys[itemsDone++]); } }; } This goes in my Backpack class public class Backpack extends Item implements Carrier, Enumeration<Object>{ The hashmap is returned by getContent(). The problem now is that eclipse keeps telling me I havent implemented the methods from Enumeration. If I use the quick fix it just adds the hasMoreElements() and nextElement() dummy methods in my class. Somehow it doesn't see these methods in the inner class.. Can anyone help me please? Any help is appreciated.

    Read the article

  • how to manage a "resource" array efficiently

    - by Haiyuan Zhang
    The senario of my question is that one need to use a fixed size of array to keep track of certain number of "objects" . The object here can be as simply as a integer or as complex as very fancy data structure. And "keep track" here means to allocate one object when other part of the app need one instance of object and recyle it for future allocation when one instance of the object is returned .Finally ,let me use c++ to put my problme in a more descriptive way . #define MAX 65535 /* 65535 just indicate that many items should be handled . performance demanding! */ typedef struct { int item ; }Item_t; Item_t items[MAX] ; class itemManager { private : /* up to you.... */ public : int get() ; /* get one index to a free Item_t in items */ bool put(int index) ; /* recyle one Item_t indicate by one index in items */ } how will you implement the two public functions of itemManager ? it's up to you to add any private member .

    Read the article

  • help me to my project [closed]

    - by latha
    hi. plz tel me to how to collect data for my project. as my projct relate to "sustainable urban infrastructure" so help me that what what data should i put to my project.i dont had any idea that how to do vit data analysis .so please direct me .

    Read the article

  • Execute Assembly from Pascal

    - by London
    How can I execute this code from Pascal : MOV EAX, variable1 PUSH EBX, EAX MOV EAX, variable2 POP EBX AND EBX, EAX Where I define method/function arguments in function(variable1, variable2). This is a school assignment I don't know why they are making us do Pascal/Assembly instead of Java/C++ or such. This is not the whole assignment I did do plenty of work before I just need help with this, any help is appreciated thank you

    Read the article

  • Problem passing strings with PHP post

    - by andy
    Hi Guys, Basically I'm developing a (very) simple search engine. You can enter a search term and you are taken to the results page - which works fine. However on the results page, I have a button that will take you to the next 10 results: where $term is the $_POST['term'] value. echo "<input type='hidden' name='term' value='" . $term . "'>"; This causes the following problem with the term is for example "aidan's". When the next 10 button is clicked, the term becomes aidan\ and no further results are found. I am not doing anything to $term. I usually use Java, but am required to use PHP for this uni assignment! Any help would be greatly appreciated.

    Read the article

  • Java - Highest, Lowest and Average

    - by Emily
    Hello, I've just started studying and I need help on one of my exercises. I need the end user to input a rain fall number for each month. I then need to out put the average rainfall, highest month and lowest month and the months which rainfall was above average. I keep getting the same number in the highest and lowest and I have no idea why. I am seriously pulling my hair out. Any help would be greatly appreciated. This is what I have so far: public class rainfall { /** * @param args */ public static void main(String[] args) { int[] numgroup; numgroup = new int [13]; ConsoleReader console = new ConsoleReader(); int highest; int lowest; int index; int tempVal; int minMonth; int minIndex; int maxMonth; int maxIndex; System.out.println("Welcome to Rainfall"); for(index = 1; index < 13; index = index + 1) { System.out.println("Please enter the rainfall for month " + index); tempVal = console.readInt(); while (tempVal>100 || tempVal<0) { System.out.println("The rating must be within 0...100. Try again"); tempVal = console.readInt(); } numgroup[index] = tempVal; } lowest = numgroup[0]; for(minIndex = 0; minIndex < numgroup.length; minIndex = minIndex + 1); { if (numgroup[0] < lowest) { lowest = numgroup[0]; minMonth = minIndex; } } highest = numgroup[1]; for(maxIndex = 0; maxIndex < numgroup.length; maxIndex = maxIndex + 1); { if (numgroup[1] > highest) { highest = numgroup[1]; maxMonth = maxIndex; } } System.out.println("The average monthly rainfall was "); System.out.println("The lowest monthly rainfall was month " + minIndex); System.out.println("The highest monthly rainfall was month " + maxIndex); System.out.println("Thank you for using Rainfall"); } private static ConsoleReader ConsoleReader() { return null; } } Thanks, Emily

    Read the article

  • MUD in python......

    - by matt
    how do you make a MUD in python can anyone help or start me of i dont have a clue on how to do if anyone knows any other source that i could use then plz let me know?

    Read the article

  • how do i search from php file ?

    - by Tum Bin
    Dear Friends, im totally new in php. Just learning. I got 2 Assingment with php and html. Assignment 01: I have to mansion some pplz name and all of them some friends name. and I have to print common friend if there have common friend. Bt there have a prob that I got also msg which dnt have any common friend like “Rana has 0 friends in common with Roni.” I want to stop this and how can i? Assignment 02: I made a html form to search a person from that php file. Like: when I will search for Rana php form will b open and and print : Rana have 4 friends and he has a common friend with Nandini and Mamun. when I will search for Tanmoy the page will be open and print: Tonmoy is Rana’s friend who have 4 friend and common friends with Nandini and Mamun. for this I have to use the function “post/get/request” Plz plz plzzzzzzzzzz help me! Here im posting my codes; <?php # Function: finfCommon function findCommon($current, $arr) { $cUser = $arr[$current]; unset($arr[$current]); foreach ($arr As $user => $friends) { $common = array(); $total = array(); foreach ($friends As $friend) { if (in_array($friend, $cUser)) { $common[] = $friend; } } $total = count($common); $add = ($total != 1) ? 's' : ''; $final[] = "<i>{$current} has {$total} friend{$add} in common with {$user}.</i>"; } return implode('<br />', $final); } # Array of users and friends $Friends = array( "Rana" => array("Pothik", "Zaman", "Tanmoy", "Ishita"), "Nandini" => array("Bonna", "Shakib", "Kamal", "Minhaj", "Ishita"), "Roni" => array("Akbar", "Anwar", "Khakan", "Pavel"), "Liton" => array("Mahadi", "Pavel"), "Mamun" => array("Meheli", "Tarek", "Zaman") ); # Creating the output value $output = "<ul>"; foreach ($Friends As $user => $friends) { $total = count($friends); $common = findCommon($user, $Friends); $output .= "<li><u>{$user} has {$total} friends.</u><br /><strong>Friends:</strong>"; if (is_array($friends) && !empty($friends[0])) { $output .= "<ul>"; foreach ($friends As $friend) { $output .= "<li>{$friend}</li>"; } $output .= "</ul>"; } $output .= "{$common}<br /><br /></li>"; } $output .= "</ul>"; # Printing the output value print $output; ?>

    Read the article

  • CSS : overflow : auto will not work under FireFox 3.6.2

    - by Michael Mao
    Hello everyone: This is a CSS related question, I got one good answer from my previous question, which suggested to use some CSS code like overflow:auto together with a fixed height container. And here is my actual implementation : on uni server Please follow the instructions on screen and buy more than 4 kinds of tickets. If you are using IE8, Opera, Safari, Chrome, you would notice that the lower right corner of the page now has a vertical scroll bar, which scrolls the content inside it and prevent it from overflowing. That's what I want to have in this section. Now the problem is, this would not do in FireFox 3.6.2. Am I doing something not compliant to the CSS standard or FireFox has its own way of overflow control? You can inspect the elements on screen, and all controlling functions are done in one javascript using jQuery. All CSS code are kept in a separated file as well. According to the professor, FireFox would be the target browser, although the version was set to 2.0...

    Read the article

  • forks in C - exercise

    - by Zka
    I try to repeat and learn more advanced uses and options when cutting trees with forks in the jungle of C. But foolishly I find an example which should be very easy as I have worked with forks before and even written some code, but i can't understand it fully. Here comes : main() { if (fork() == 0) { if (fork() == 0) { printf("3"); } else if ((wait(NULL)) > 0) { printf("2"); } } else { if (fork() == 0) { printf("1"); exit(0); } if (fork() == 0) { printf("4"); } } printf("0"); return 0; } Possible solutions are : 3201040 3104200 1040302 4321000 4030201 1403020 where 2, 5 and 6 are correct answers. First of all, shouldn't there be four zeroes in the output? Second... How does one come to the solution at all? Been doing this on paper for almost an hour and I'm not even close to understanding why the given solution are more correct than the false ones (except for nr3 as it can't end with 2 since a 0 must follow). Anyone with his forks in check who can offer some good explanation?

    Read the article

  • Entry lvl. COBOL Control Breaks

    - by Kyle Benzle
    I'm working in COBOL with a double control break to print a hospital record. The input is one record per line, with, hospital info first, then patient info. There are multiple records per hospital, and multiple services per patient. The idea is, using a double control break, to print one hospital name, then all the patients from that hospital. Then print the patient name just once for all services, like the below. I'm having trouble with my output, and am hoping someone can help me get it in order. I am using AccuCobol to compile experts-exchange does not allow .cob and .dat so the extentions were changed to .txt The files are: the .cob lab5b.cob the input / output: lab5bin.dat, lab5bout.dat The assignment: http://www.cse.ohio-state.edu/~sgomori/314/lab5.html Hospital Number: 001 Hospital Name: Mount Carmel 00001 Griese, Brian Ear Infection 08/24/1999 300.00 Diaper Rash 09/05/1999 25.00 Frontal Labotomy 09/25/1999 25,000.00 Rear Labotomy 09/26/1999 25,000.00 Central Labotomy 09/28/1999 24,999.99 The total amount owed for this patient is: $.......... (End of Hospital) The total amount owed for this hospital is: $......... enter code here IDENTIFICATION DIVISION. PROGRAM-ID. LAB5B. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT FILE-IN ASSIGN TO 'lab5bin.dat' ORGANIZATION IS LINE SEQUENTIAL. SELECT FILE-OUT ASSIGN TO 'lab5bout.dat' ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD FILE-IN. 01 HOSPITAL-RECORD-IN. 05 HOSPITAL-NUMBER-IN PIC 999. 05 HOSPITAL-NAME-IN PIC X(20). 05 PATIENT-NUMBER-IN PIC 99999. 05 PATIENT-NAME-IN PIC X(20). 05 SERVICE-IN PIC X(30). 05 DATE-IN PIC 9(8). 05 OWED-IN PIC 9(7)V99. FD FILE-OUT. 01 REPORT-REC-OUT PIC X(100). WORKING-STORAGE SECTION. 01 WS-WORK-AREAS. 05 WS-HOLD-HOSPITAL-NUM PIC 999 VALUE ZEROS. 05 WS-HOLD-PATIENT-NUM PIC 99999 VALUE ZEROS. 05 ARE-THERE-MORE-RECORDS PIC XXX VALUE 'YES'. 88 MORE-RECORDS VALUE 'YES'. 88 NO-MORE-RECORDS VALUE 'NO '. 05 FIRST-RECORD PIC XXX VALUE 'YES'. 05 WS-PATIENT-TOTAL PIC 9(9)V99 VALUE ZEROS. 05 WS-HOSPITAL-TOTAL PIC 9(9)V99 VALUE ZEROS. 05 WS-PAGE-CTR PIC 99 VALUE ZEROS. 01 WS-DATE. 05 WS-YR PIC 9999. 05 WS-MO PIC 99. 05 WS-DAY PIC 99. 01 HL-HEADING1. 05 PIC X(49) VALUE SPACES. 05 PIC X(14) VALUE 'OHIO INSURANCE'. 05 PIC X(7) VALUE SPACES. 05 HL-PAGE PIC Z9. 05 PIC X(14) VALUE SPACES. 05 HL-DATE. 10 HL-MO PIC 99. 10 PIC X VALUE '/'. 10 HL-DAY PIC 99. 10 PIC X VALUE '/'. 10 HL-YR PIC X VALUE '/'. 01 HL-HEADING2. 05 PIC XXXXXXXXXX VALUE 'HOSPITAL: '. 05 HL-HOSPITAL PIC 999. 01 HL-HEADING3. 05 PIC X(7) VALUE "Patient". 05 PIC X(3) VALUE SPACES. 05 PIC X(7) VALUE "Patient". 05 PIC X(39) VALUE SPACES. 05 PIC X(7) VALUE "Date of". 05 PIC X(3) VALUE SPACES. 05 PIC X(6) VALUE "Amount". 01 HL-HEADING4. 05 PIC X(6) VALUE "Number". 05 PIC X(4) VALUE SPACES. 05 PIC X(4) VALUE "Name". 05 PIC X(18) VALUE SPACES. 05 PIC X(10) VALUE "Service". 05 PIC X(14) VALUE SPACES. 05 PIC X(8) VALUE "Service". 05 PIC X(2) VALUE SPACES. 05 PIC X(5) VALUE "Owed". 01 DL-PATIENT-LINE. 05 PIC X(28) VALUE SPACES. 05 DL-PATIENT-NUMBER PIC XXXXX. 05 PIC X(21) VALUE SPACES. 05 DL-PATIENT-TOTAL PIC $$$,$$$,$$9.99. 01 DL-HOSPITAL-LINE. 05 PIC X(47) VALUE SPACES. 05 PIC X(16) VALUE 'HOSPITAL TOTAL: '. 05 DL-HOSPITAL-TOTAL PIC $$$,$$$,$$9.99. PROCEDURE DIVISION. 100-MAIN-MODULE. PERFORM 600-INITIALIZATION-RTN PERFORM UNTIL NO-MORE-RECORDS READ FILE-IN AT END MOVE 'NO ' TO ARE-THERE-MORE-RECORDS NOT AT END PERFORM 200-DETAIL-RTN END-READ END-PERFORM PERFORM 400-HOSPITAL-BREAK PERFORM 700-END-OF-JOB-RTN STOP RUN. 200-DETAIL-RTN. EVALUATE TRUE WHEN FIRST-RECORD = 'YES' MOVE PATIENT-NUMBER-IN TO WS-HOLD-PATIENT-NUM MOVE HOSPITAL-NUMBER-IN TO WS-HOLD-HOSPITAL-NUM PERFORM 500-HEADING-RTN MOVE 'NO ' TO FIRST-RECORD WHEN HOSPITAL-NUMBER-IN NOT = WS-HOLD-HOSPITAL-NUM PERFORM 400-HOSPITAL-BREAK WHEN PATIENT-NUMBER-IN NOT = WS-HOLD-PATIENT-NUM PERFORM 300-PATIENT-BREAK END-EVALUATE ADD OWED-IN TO WS-PATIENT-TOTAL. 300-PATIENT-BREAK. MOVE WS-PATIENT-TOTAL TO DL-PATIENT-TOTAL MOVE WS-HOLD-PATIENT-NUM TO DL-PATIENT-NUMBER WRITE REPORT-REC-OUT FROM DL-PATIENT-LINE AFTER ADVANCING 2 LINES ADD WS-PATIENT-TOTAL TO WS-HOSPITAL-TOTAL IF MORE-RECORDS MOVE ZEROS TO WS-PATIENT-TOTAL MOVE PATIENT-NUMBER-IN TO WS-HOLD-PATIENT-NUM END-IF. 400-HOSPITAL-BREAK. PERFORM 300-PATIENT-BREAK MOVE WS-HOSPITAL-TOTAL TO DL-HOSPITAL-TOTAL WRITE REPORT-REC-OUT FROM DL-HOSPITAL-LINE AFTER ADVANCING 2 LINES IF MORE-RECORDS MOVE ZEROS TO WS-HOSPITAL-TOTAL MOVE HOSPITAL-NUMBER-IN TO WS-HOLD-HOSPITAL-NUM PERFORM 500-HEADING-RTN END-IF. 500-HEADING-RTN. ADD 1 TO WS-PAGE-CTR MOVE WS-PAGE-CTR TO HL-PAGE MOVE WS-HOLD-HOSPITAL-NUM TO HL-HOSPITAL WRITE REPORT-REC-OUT FROM HL-HEADING1 AFTER ADVANCING PAGE WRITE REPORT-REC-OUT FROM HL-HEADING2 AFTER ADVANCING 2 LINES. WRITE REPORT-REC-OUT FROM HL-HEADING3 AFTER ADVANCING 2 LINES. 600-INITIALIZATION-RTN. OPEN INPUT FILE-IN OUTPUT FILE-OUT *159 ACCEPT WS-DATE FROM DATE YYYYMMDD MOVE WS-YR TO HL-YR MOVE WS-MO TO HL-MO MOVE WS-DAY TO HL-DAY. 700-END-OF-JOB-RTN. CLOSE FILE-IN FILE-OUT.

    Read the article

  • big O notation algorithm

    - by niggersak
    Use big-O notation to classify the traditional grade school algorithms for addition and multiplication. That is, if asked to add two numbers each having N digits, how many individual additions must be performed? If asked to multiply two N-digit numbers, how many individual multiplications are required? . Suppose f is a function that returns the result of reversing the string of symbols given as its input, and g is a function that returns the concatenation of the two strings given as its input. If x is the string hrwa, what is returned by g(f(x),x)? Explain your answer - don't just provide the result!

    Read the article

  • templates of functions

    - by anotr67
    I'm told to create template of function , that will take 4 arguments : pointer reference pointer to array pointer to function How to perform this task ? I was trying : template<typename TYPE> TYPE biggest(TYPE *L, TYPE $M, TYPE *K[], TYPE *O()) { } but it is wrong.

    Read the article

  • what is order notation f(n)=O(g(n))?

    - by Lopa
    2 questions: question 1: under what circumstances would this[O(f(n))=O(k.f(n))] be the most appropriate form of time-complexity analysis? question 2: working from mathematical definition of O notation, show that O(f(n))=O(k.f(n)), for positive constant k.? My view: For the first one I think it is average case and worst case form of time-complexity. am i right? and what else do i write in that? for the second one I think we need to define the function mathematically, so is the answer something like because the multiplication by a constant just corresponds to a readjustment of value of the arbitrary constant 'k' in definition of O.

    Read the article

  • How does this code break the Law of Demeter?

    - by Dave Jarvis
    The following code breaks the Law of Demeter: public class Student extends Person { private Grades grades; public Student() { } /** Must never return null; throw an appropriately named exception, instead. */ private synchronized Grades getGrades() throws GradesException { if( this.grades == null ) { this.grades = createGrades(); } return this.grades; } /** Create a new instance of grades for this student. */ protected Grades createGrades() throws GradesException { // Reads the grades from the database, if needed. // return new Grades(); } /** Answers if this student was graded by a teacher with the given name. */ public boolean isTeacher( int year, String name ) throws GradesException, TeacherException { // The method only knows about Teacher instances. // return getTeacher( year ).nameEquals( name ); } private Grades getGradesForYear( int year ) throws GradesException { // The method only knows about Grades instances. // return getGrades().getForYear( year ); } private Teacher getTeacher( int year ) throws GradesException, TeacherException { // This method knows about Grades and Teacher instances. A mistake? // return getGradesForYear( year ).getTeacher(); } } public class Teacher extends Person { public Teacher() { } /** * This method will take into consideration first name, * last name, middle initial, case sensitivity, and * eventually it could answer true to wild cards and * regular expressions. */ public boolean nameEquals( String name ) { return getName().equalsIgnoreCase( name ); } /** Never returns null. */ private synchronized String getName() { if( this.name == null ) { this.name == ""; } return this.name; } } Questions How is the LoD broken? Where is the code breaking the LoD? How should the code be written to uphold the LoD?

    Read the article

  • bash : recursive listing of all files problem

    - by Michael Mao
    Run a recursive listing of all the files in /var/log and redirect standard output to a file called lsout.txt in your home directory. Complete this question WITHOUT leaving your home directory. An: ls -R /var/log/ /home/bqiu/lsout.txt I reckon the above bash command is not correct. This is what I've got so far: $ ls -1R .: cal.sh cokemachine.sh dir sort test.sh ./dir: afile.txt file subdir ./dir/subdir: $ ls -R | sed s/^.*://g cal.sh cokemachine.sh dir sort test.sh afile.txt file subdir But this still leaves all directory/sub-directory names (dir and subdir), plus a couple of empty newlines How could I get the correct result without using Perl or awk? Preferably using only basic bash commands(this is just because Perl and awk is out of assessment scope)

    Read the article

  • An algorithm for pavement usage calculation

    - by student
    Given an area of specific size I need to find out how many pavement stones to use to completely pave the area. Suppose that I have an empty floor of 100 metre squares and stones with 20x10 cm and 30x10 cm sizes. I must pave the area with minimum usage of stones of both sizes. Anyone knows of an algorithm that calculates this? (Sorry if my English is bad) C# is preferred.

    Read the article

  • How do you display a binary search tree?

    - by fakeit
    I'm being asked to display a binary search tree in sorted order. The nodes of the tree contain strings. I'm not exactly sure what the best way is to attack this problem. Should I be traversing the tree and displaying as I go? Should I flatten the tree into an array and then use a sorting algorithm before I display? I'm not looking for the actual code, just a guide where to go next.

    Read the article

  • How can I reverse a stack?

    - by come pollinate me
    I need to write a VB.NET code to reverse the given characters using a stack. Input: 'S','T','A','C','K' So far I have input the letters, but I don't know how to get the console to reverse it. I'm a beginner to programming so please excuse my ignorance. An explanation as to how it's done would also be greatly appreciated. What I got so far. Module Module1 Sub Main() Dim StackObject As New Stack StackObject.Push("S") Console.WriteLine(StackObject.Peek) StackObject.Push("T") Console.WriteLine(StackObject.Peek) StackObject.Push("A") Console.WriteLine(StackObject.Peek) StackObject.Push("C") Console.WriteLine(StackObject.Peek) StackObject.Push("K") Console.WriteLine(StackObject.Peek) End Sub End Module I just need it to be reversed. I got it!! Module Module1 Sub Main() Dim StackObject As New Stack StackObject.Push("S") StackObject.Push("T") StackObject.Push("A") StackObject.Push("C") StackObject.Push("K") For Each cur As String In StackObject Console.WriteLine(cur) Next End Sub End Module That's how it's done.

    Read the article

  • about Quick Sort

    - by matin1234
    Hi I have written this code but it will print these stack traces in the console please help me thanks! (Aslo "p" and "q" are the first and last index of our array ,respectively) public class JavaQuickSort { public static void QuickSort(int A[], int p, int q) { int i, last = 0; Random rand = new Random(); if (q < 1) { return; } **swap(A, p, rand.nextInt() % (q+1));** for (i = p + 1; i <= q; i++) { if (A[i] < A[p]) { swap(A, ++last, i); } } swap(A, p, last); QuickSort(A, p, last - 1); QuickSort(A, last + 1, q); } private static void swap(int[] A, int i, int j) { int temp; temp = A[i]; **A[i] = A[j];** A[j] = temp; } public static void main(String[] args){ int[] A = {2,5,7,3,9,0,1,6,8}; **QuickSort(A, 0,8 );** System.out.println(Arrays.toString(A)); } } the Stack traces : run: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -3 at JavaQuickSort.swap(JavaQuickSort.java:38) at JavaQuickSort.QuickSort(JavaQuickSort.java:22) at JavaQuickSort.main(JavaQuickSort.java:45) Java Result: 1 BUILD SUCCESSFUL (total time: 2 seconds) I also bold those statements that cause these stack traces. like == ** ...**

    Read the article

  • Algorithm to generate a list of unique combinations based on a list of numbers

    - by ross
    I would like to efficiently generate a unique list of combinations of numbers based on a starting list of numbers. example start list = [1,2,3,4,5] but the algorithm should work for [1,2,3...n] result = [1],[2],[3],[4],[5] [1,2],[1,3],[1,4],[1,5] [1,2,3],[1,2,4],[1,2,5] [1,3,4],[1,3,5],[1,4,5] [2,3],[2,4],[2,5] [2,3,4],[2,3,5] [3,4],[3,5] [3,4,5] [4,5] Note. I don't want duplicate combinations, although I could live with them, eg in the above example I don't really need the combination [1,3,2] because it already present as [1,2,3]

    Read the article

  • Thread scheduling C

    - by MRP
    include <pthread.h> include <stdio.h> include <stdlib.h> #define NUM_THREADS 4 #define TCOUNT 5 #define COUNT_LIMIT 13 int done = 0; int count = 0; int thread_ids[4] = {0,1,2,3}; int thread_runtime[4] = {0,5,4,1}; pthread_mutex_t count_mutex; pthread_cond_t count_threshold_cv; void *inc_count(void *t) { int i; long my_id = (long)t; long run_time = thread_runtime[my_id]; if (my_id==2 && done ==0) { for(i=0; i< 5 ; i++) { if( i==4 ){done =1;} pthread_mutex_lock(&count_mutex); count++; if (count == COUNT_LIMIT) { pthread_cond_signal(&count_threshold_cv); printf("inc_count(): thread %ld, count = %d Threshold reached.\n", my_id, count); } printf("inc_count(): thread %ld, count = %d, unlocking mutex\n", my_id, count); pthread_mutex_unlock(&count_mutex); } } if (my_id==3 && done==1) { for(i=0; i< 4 ; i++) { if(i == 3 ){ done = 2;} pthread_mutex_lock(&count_mutex); count++; if (count == COUNT_LIMIT) { pthread_cond_signal(&count_threshold_cv); printf("inc_count(): thread %ld, count = %d Threshold reached.\n", my_id, count); } printf("inc_count(): thread %ld, count = %d, unlocking mutex\n", my_id, count); pthread_mutex_unlock(&count_mutex); } } if (my_id==4&& done == 2) { for(i=0; i< 8 ; i++) { pthread_mutex_lock(&count_mutex); count++; if (count == COUNT_LIMIT) { pthread_cond_signal(&count_threshold_cv); printf("inc_count(): thread %ld, count = %d Threshold reached.\n",my_id, count); } printf("inc_count(): thread %ld, count = %d, unlocking mutex\n", my_id, count); pthread_mutex_unlock(&count_mutex); } } pthread_exit(NULL); } void *watch_count(void *t) { long my_id = (long)t; printf("Starting watch_count(): thread %ld\n", my_id); pthread_mutex_lock(&count_mutex); if (count<COUNT_LIMIT) { pthread_cond_wait(&count_threshold_cv, &count_mutex); printf("watch_count(): thread %ld Condition signal received.\n", my_id); count += 125; printf("watch_count(): thread %ld count now = %d.\n", my_id, count); } pthread_mutex_unlock(&count_mutex); pthread_exit(NULL); } int main (int argc, char *argv[]) { int i, rc; long t1=1, t2=2, t3=3, t4=4; pthread_t threads[4]; pthread_attr_t attr; pthread_mutex_init(&count_mutex, NULL); pthread_cond_init (&count_threshold_cv, NULL); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE); pthread_create(&threads[0], &attr, watch_count, (void *)t1); pthread_create(&threads[1], &attr, inc_count, (void *)t2); pthread_create(&threads[2], &attr, inc_count, (void *)t3); pthread_create(&threads[3], &attr, inc_count, (void *)t4); for (i=0; i<NUM_THREADS; i++) { pthread_join(threads[i], NULL); } printf ("Main(): Waited on %d threads. Done.\n", NUM_THREADS); pthread_attr_destroy(&attr); pthread_mutex_destroy(&count_mutex); pthread_cond_destroy(&count_threshold_cv); pthread_exit(NULL); } so this code creates 4 threads. thread 1 keeps track of the count value while the other 3 increment the count value. the run time is the number of times the thread will increment the count value. I have a done value that allows the first thread to increment the count value first until its run time is up.. so its like a First Come First Serve. my question is, is there a better way of implementing this? I have read about SCHED_FIFO or SCHED_RR.. I guess I dont know how to implement them into this code or if it can be.

    Read the article

  • How do I convert text to XML in C?

    - by pedro
    How can I make a program that opens a text file, and converts it into a XML file? The XML might look like: <curso> <sigla>LTCGM</sigla> <NAlunos>1</NAlunos> <lista_alunos> <aluno> <numero>6567</numero> <nome>Artur Pereira Ribeiro</nome> <email>[email protected]</email> <estado>Aprovado</estado> <media_notas>13</media_notas> <maior_nota>16</maior_nota> <menor_nota>11</menor_nota> </aluno> </lista_alunos> </curso>

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >