dev-cpp-users Mailing List for Dev-C++ (Page 8)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(15) |
Oct
(115) |
Nov
(154) |
Dec
(258) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(377) |
Feb
(260) |
Mar
(249) |
Apr
(188) |
May
(152) |
Jun
(150) |
Jul
(195) |
Aug
(202) |
Sep
(200) |
Oct
(286) |
Nov
(242) |
Dec
(165) |
2002 |
Jan
(245) |
Feb
(241) |
Mar
(239) |
Apr
(346) |
May
(406) |
Jun
(369) |
Jul
(418) |
Aug
(357) |
Sep
(362) |
Oct
(597) |
Nov
(455) |
Dec
(344) |
2003 |
Jan
(446) |
Feb
(397) |
Mar
(515) |
Apr
(524) |
May
(377) |
Jun
(387) |
Jul
(532) |
Aug
(364) |
Sep
(294) |
Oct
(352) |
Nov
(295) |
Dec
(327) |
2004 |
Jan
(416) |
Feb
(318) |
Mar
(324) |
Apr
(249) |
May
(259) |
Jun
(218) |
Jul
(212) |
Aug
(259) |
Sep
(158) |
Oct
(162) |
Nov
(214) |
Dec
(169) |
2005 |
Jan
(111) |
Feb
(165) |
Mar
(199) |
Apr
(147) |
May
(131) |
Jun
(163) |
Jul
(235) |
Aug
(136) |
Sep
(84) |
Oct
(88) |
Nov
(113) |
Dec
(100) |
2006 |
Jan
(85) |
Feb
(119) |
Mar
(33) |
Apr
(31) |
May
(56) |
Jun
(68) |
Jul
(18) |
Aug
(62) |
Sep
(33) |
Oct
(55) |
Nov
(19) |
Dec
(40) |
2007 |
Jan
(22) |
Feb
(49) |
Mar
(34) |
Apr
(51) |
May
(66) |
Jun
(43) |
Jul
(116) |
Aug
(57) |
Sep
(70) |
Oct
(69) |
Nov
(97) |
Dec
(86) |
2008 |
Jan
(32) |
Feb
(47) |
Mar
(106) |
Apr
(67) |
May
(28) |
Jun
(39) |
Jul
(31) |
Aug
(25) |
Sep
(18) |
Oct
(25) |
Nov
(5) |
Dec
(21) |
2009 |
Jan
(33) |
Feb
(27) |
Mar
(27) |
Apr
(22) |
May
(22) |
Jun
(10) |
Jul
(17) |
Aug
(9) |
Sep
(21) |
Oct
(13) |
Nov
(4) |
Dec
(11) |
2010 |
Jan
(10) |
Feb
(8) |
Mar
(4) |
Apr
(1) |
May
|
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(26) |
Nov
(9) |
Dec
(1) |
2011 |
Jan
(21) |
Feb
(16) |
Mar
(4) |
Apr
(19) |
May
(26) |
Jun
(9) |
Jul
(6) |
Aug
|
Sep
(4) |
Oct
(3) |
Nov
(2) |
Dec
(1) |
2012 |
Jan
(4) |
Feb
(7) |
Mar
(4) |
Apr
|
May
(1) |
Jun
(10) |
Jul
(1) |
Aug
(1) |
Sep
(18) |
Oct
(3) |
Nov
(1) |
Dec
(1) |
2013 |
Jan
(4) |
Feb
(2) |
Mar
(15) |
Apr
(6) |
May
(1) |
Jun
(3) |
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
|
Nov
(9) |
Dec
|
2014 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(4) |
2015 |
Jan
(2) |
Feb
(3) |
Mar
(1) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(2) |
Oct
(9) |
Nov
(35) |
Dec
(6) |
2016 |
Jan
(7) |
Feb
(10) |
Mar
(10) |
Apr
(9) |
May
(13) |
Jun
(9) |
Jul
(1) |
Aug
(3) |
Sep
(3) |
Oct
(1) |
Nov
(1) |
Dec
|
2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Jordan B. <jor...@me...> - 2011-05-06 19:50:25
|
I have the below files iin visaul studio and it keeps advising me that I am missing a ';' before using or it will say I am missing a ';' after std and I can not find what the heck it is talking about. I know what the std and using is and as you can see from the code it is the correct places and spelled correctly. When put in another compiler it works fine. Any hep would be great. *************Below is the file in the "source file" folder****************************** <code> //Created: 05-06-2011 #include "task.h" #include <iostream> #include <cstdlib> using namespace std; int main() { char clientcode[8] = {'A','B','C','D','E','F'}; string name = "FIRST TEST PROCESS!!! DATA WILL NOT BE SAVED"; task t = task(clientcode, name); return 0;} </code> ***********************************END OF FILE********************************** BELOW THESE FILES ARE IN THE HEADER FILES ****************CLASS(SPECIFICATION*********************************************** <code> //Robert Burnam // Created: 05-03-2011 //This is the specification file for my task class #include <iostream> #include <cstdlib> using namespace std; class task { private: string taskName; string taskDescription; int UID; char clientCode[8]; int numstep; char answer; bool correct; struct step { int stepNum; string Instruction; }; step instructions [50]; tm timeinfo; tm TODAY; tm YESTERDAY; bool DUE; bool LATE; bool DONE; void setUID(); //This will set a random number as the UID for this task and so it is not altered this is a private functon public: task(char clientcode [], string processname); //This function will create a new task and prompt the user for the intput for each field; int getUID(); //This function will return the UID of this task. string getName(); //This function will return a string which is the name of this task void changeName(); //This function will prompt the user to change the name of this task string getClientCode(); //This function will return the clientCode array as a string for the useer to see void changeDescription(); //This will prompt the user what the description is now and allow them to change it. string getDescription(); //This will get the description and return it as a string to the main function. void ChangeInstructions(); //This function will prompt the user to change the Insturctions for the class step by step void displayInstructions(); //This will display the instructions step by step for this task void changeDueTime(); //This function will prompt the user to change the time that the task is due. bool isDue(); //This function will decide wether or not the task is due ( will be true up to ten mintues fo the task being do) bool isLate(); //This function will decide if the task is late (this is only based off of time not date!) bool isDone(); // THis function returns wether the task has been completed or not </code> *******************END OF CLASS*************************** *************************Implementation File of class********************* //Robert Burnam //Created: 05-06-2011 //This is the implementation of the task program #include "task.h" #include <windows.h> #include <string> using namespace std; task :: task(char clientcode [], string processname) { cout << "You are now creating a new task for " << clientcode <<"." << endl; cout << "This task if for " << processname << " processing." <<endl; cout << "This task should be only somewhat specific and not too general." <<endl; cout << " For example, if you have to do Bankruptcies and Demographics for this client code, It may be better to use only one task for each one of the " << processname << "." << endl; //set the name of the task cout << "Now, we will need to fill in some information before this task can be completed." << endl; cout << "Anything before the colon below will describe what you are entering and will show any restrictions to what you can enter, in parathesis, if there are any." << endl; cout << "Name:" ; //cin >> taskName; cout << endl; cout << "Comments(if you do not have any type \" none \". Then press enter): " << endl; //cin >> taskDescription; cout <<"This takes care of the easy parts of creating this task. The next step will involve filling in each step indivivualy." << endl; cout << "If you need sometime to decide how many steps you will need and in which order they will be entered, please take your time as I will wait till time indefinite for your input!" << endl; cout << "I will first ask how many steps there are and then you are to enter the steps in numerical order you would like them to be listed starting with 1." << endl; do{ cout << " How many steps are there for this task to be completed?: "; cin >> numstep; cout << " It seems that I am going to be creating " << numstep << "." <<endl; cout << " If this is correct press y(yes) or n(no): "; cin >> answer; }while(correct == false); cout << endl; cout << "One moment, I am creating " << numstep << "s, should not take to long." << endl; } </code> ****************END OF IMPLEMENTATION FILE******** } |
From: William Mc C. <wil...@ms...> - 2011-05-06 09:52:08
|
http://plc-seeders.org/goods.html |
From: Per W. <pw...@ia...> - 2011-05-03 14:09:24
|
Yes, there are a number of n-log-n sorting algorithms. But there are no algorithm better than n-log-n. So worrying about the linear transfer times from moving list elements into a vector of pointers and then back again can not be a time issue when debating choices. Next thing is that many n-log-n algorithms does require direct-access to elements. If requiring traversals to locate the elements, then they will no longer be n-log-n. But a person who spends an hour or two with Google looking for different sort algorithms and looking for specific help on sorting lists should be able to quickly get a good view of what is recommendable solutions - obviously taking into account if the lists are always small or if the lists may have tens of thousands of entries where O(n^2) may be hundreds of times slower than O(n log n). If the OP did do as I suggested, he would be able to find the following (or similar) information about merge-sort (quote is from wikipedia but other sources of sorting algorithms would come to similar results): "Merge sort is often the best choice for sorting a linked list: in this situation it is relatively easy to implement a merge sort in such a way that it requires only .(1) extra space, and the slow random-access performance of a linked list makes some other algorithms (such as quicksort) perform poorly, and others (such as heapsort) completely impossible." So in my previous post, I was trying to debate two different things: The first thing I wanted to make clear was that a multipass solution (like copying data to an array) can match a single-pass algorithm since O(n) + O(n log n) + O (n) is still just O(n log n). And that a linked list means objects are accessed using pointers meaning that the array only needs to store these pointers and not the full node content. The second thing I wanted to make clear was that the net have lots of documentation about sort algorithms and about sorting of linked lists. So someone who don't know what to do can get far with quite limited time spent googling. Mailing lists and web forum are then great choices to ask questions if someone gets stuck after having spent that initial time reading up on a couple of available choices. It is way easier when someone comes back and say: "I have been trying to implement an insertion sort (since it is fast enough for my needs of no more than 100 elements) but now are stuck trying to ..." /pwm On Tue, 3 May 2011 mol...@se... wrote: > > > ------------ Pùvodní zpráva ------------ > > Od: Per Westermark <pw...@ia...> > > Pøedmìt: Re: [Dev-C++] Sorting Linked Lists and Array Members > > Datum: 03.5.2011 11:39:34 > > ---------------------------------------- > > It is very fast to walk through a linked list once and copy the element > > pointers into an array. That is a linear operation - one extra step for > > every extra element. > > > > Sorting an array taks n-log-n time which is the best possible for sorting. > > > > Rebuilding the linked list is one walk through the array, so linear time. > > > > So using an array is a good sorting method. > > > > Now try Google and look at bubble sort, insertion sort, merge sort, ... > > Merge sort is also n*logn; in fact it's often used on arrays as well. > The fact that sorting list in place may be slower than using temporary > array is because it needs more cpu instructions to traverse/manipulate a > list than an array. > > ------------------------------------------------------------------------------ > WhatsUp Gold - Download Free Network Management Software > The most intuitive, comprehensive, and cost-effective network > management toolset available today. Delivers lowest initial > acquisition cost and overall TCO of any competing solution. > http://p.sf.net/sfu/whatsupgold-sd > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
From: <mol...@se...> - 2011-05-03 13:41:36
|
> ------------ Původní zpráva ------------ > Od: Per Westermark <pw...@ia...> > Předmět: Re: [Dev-C++] Sorting Linked Lists and Array Members > Datum: 03.5.2011 11:39:34 > ---------------------------------------- > It is very fast to walk through a linked list once and copy the element > pointers into an array. That is a linear operation - one extra step for > every extra element. > > Sorting an array taks n-log-n time which is the best possible for sorting. > > Rebuilding the linked list is one walk through the array, so linear time. > > So using an array is a good sorting method. > > Now try Google and look at bubble sort, insertion sort, merge sort, ... Merge sort is also n*logn; in fact it's often used on arrays as well. The fact that sorting list in place may be slower than using temporary array is because it needs more cpu instructions to traverse/manipulate a list than an array. |
From: Per W. <pw...@ia...> - 2011-05-03 08:52:05
|
Large numbers of posts here. Note 1: School assignments are intended to be solved by the student. The student is intended to have the required knowledge to manage the tasks. Many schools do follow mailing lists and web forums (google works well for that) to catch students that offloads their work on the net. Note 2: Standard debugging work includes identifying corner cases. Things like: - what happens if first element is inserted/removed? - what happens if last element is inserted/removed? - what happens if internal (not first/last) element is inserted/removed? - what happens if there is no match? Should be trivial to step through the code in a debugger for the above four cases and see what happens. Note that if you have one pointer that is your "list" and points to the first element - what do you do when you remove this element? Note 3: You don't seem to have tried Google for finding information about how to sort linked lists. There is huge amounts of information. Note 4: You worry about time for copying if using a array for the sorting. But that means that you haven't spent any time learning about ordo - the cost of operations taking constant time O(1), proportional time O(n), quadratic time O(n^2) etc. It is very fast to walk through a linked list once and copy the element pointers into an array. That is a linear operation - one extra step for every extra element. Sorting an array taks n-log-n time which is the best possible for sorting. Rebuilding the linked list is one walk through the array, so linear time. So using an array is a good sorting method. Now try Google and look at bubble sort, insertion sort, merge sort, ... Now what do you find about efficiency? Do you still worry about any copying? You do realize that you only need to copy pointers - not any real content of the individual list elements? Note 5: Just about every function you are requested to add to your program ends up as a help request to this list. Isn't that a bit strange? Does your class mates also needs their own web forum or mailing list to get through? Or maybe they have looked in books about computer algorithms or have tried Google? Or just spends a bit more time debugging their code? Real programming means developers who sits and spends their own time solving problems. The world would ground to a stand-still if all development required people to ask for help on the net - and who would be competent enough to answer the questions if people don't learn to solve their own problems? Experience can't help, because bigger experience just means people starts working on more complex probems until they reach a level where they can't trivially write code but just have to spend lots of own time fighting with the problems at hand. When looking for a job, the job interview will focus a lot on your ability to solve problems. And many companies will not allow you to discuss your projects on the net, making it very hard to ask for magical online help. What would you do if you googled and found posts where developers from a major elevator manufactuer asks for help since they don't know how to safely calculate and regulate the speed of an elevator? If the developers for a car manufactuers asks about help on anti-lock break system configuration? If the alarm clock manufacturer needs help how to implement snooze functionality? /pwm On Mon, 2 May 2011, Jordan Burnam wrote: > Hey Everyone, > > I have the following function that I am implementing within a list class in order to be able to sort them. This list should sort the char array elements by the alphabet but so far have had little luck to implement this. At this point I know that I cannot compare the two values of the array with the ">" operand but if I type cast it to an int but then I also get the lowercase ASCII value for each letter and make it a constant to figure out which one goes first I could do it this way but there has to be an easier way to do this. Below I have pasted the entire program as to make it easier to understand the context of the function, the function in question is the very last one named "list_selection_sort". Any idea or comments would be much appreciated. > > Thanks, > Jordan > > <code> > > > > void list_selection_sort(Node_ptr &a_list) > > { > > Node_ptr currNode; > Node_ptr nextNode; > Node_ptr lastNode; > > int itiems = 1; > > > > > > currNode = a_list; > > while(currNode ->ptr_to_next_node != NULL) > > { > > currNode = currNode ->ptr_to_next_node; > > itiems++; > > > > } > > lastNode = currNode; > currNode = a_list; > nextNode = currNode ->ptr_to_next_node; > > while (itiems > 0) > { > if(currNode -> word[0] > nextNode -> word[0]) > { > curr > > > } > > else > { lastNode = currNode; > currNode = currNode ->ptr_to_next_node; > nextNode = currNode ->ptr_to_next_node;} > itiems--; > } > > system("pause"); > > } > > <\code> |
From: William Mc C. <wil...@ms...> - 2011-05-03 01:12:04
|
http://emisiontdt.com/goods.html |
From: Michal M. <mol...@se...> - 2011-05-02 18:22:51
|
Simple (bubble)sort can look like this: void swap(Node_ptr &list, Node_ptr n, Node_ptr next, Node_ptr prev) { n->ptr_to_next_node = next->ptr_to_next_node; next->ptr_to_next_node = n; if (prev) { prev->ptr_to_next_node = next; } else { /* we're at first node */ list = next; } } void sort(Node_ptr &list) { bool swapped; do { swapped = false; for (Node_ptr n = list, prev = NULL; n && n->ptr_to_next_node; prev = n, n = n->ptr_to_next_node) { Node_ptr next = n->ptr_to_next_node; if (strcmp(n->word, next->word) > 0) { swap(list, n, next, prev); swapped = true; } } } while (swapped); } |
From: Michal M. <mol...@se...> - 2011-05-02 06:30:58
|
Sorry for the formatting Dne 2.5.2011 4:33, Jordan Burnam napsal(a): > void linklist::append(int num) > { > node *newNode = new node; > node *nextNode = new node; > if (p == NULL) > { > p = newNode; > p ->data = num; > p->link = NULL; > } > > else { // missing > newNode = new node; > node * n = p; > while(n -> link){n = n -> link;} > n-> link = newNode; > > newNode -> data = num; > newNode -> link = NULL; } // missing > } > void linklist::next( int c, int num) > { > node *lastNode; you never read value of lastNode so can get rid of it > node *currNode; > node *nextNode; > > currNode = p; > lastNode = currNode; > nextNode = currNode -> link; the line above will fail if the list is empty, you should check that situation > > while(c != 0) > { > lastNode = currNode; > currNode = currNode -> link; > nextNode = currNode -> link; > c--; OK, but you should check if you are still inside the list if (currNode == NULL) { cerr << "linklist::next: outside the list" << endl; return; } > } > > node *newNode; > newNode = new node; > newNode -> data = num; > > currNode -> link = newNode; > newNode -> link = nextNode; > > } void linklist::del( int num ) { node * lastNode; node * currNode; currNode = p; lastNode = NULL; while(currNode != NULL) { if(currNode -> data == num) { if (lastNode) { lastNode->link = currNode->link; delete currNode; } else { // it was the first node in the list node* n = p; p = p->link; delete n; } return; } else { // should be here although it accidentally works even without them lastNode = currNode; currNode = currNode -> link; } // should be here although it accidentally works even without them } // if } // while cout << "Item not found" << endl; } > void linklist::display() should be OK int linklist:: count () { int count =0; node *a_node; a_node = p; while(a_node != NULL) { count++; a_node = a_node -> link; } return count;} |
From: Jordan B. <jor...@me...> - 2011-05-02 02:48:07
|
Hey Everyone, I have the following function that I am implementing within a list class in order to be able to sort them. This list should sort the char array elements by the alphabet but so far have had little luck to implement this. At this point I know that I cannot compare the two values of the array with the ">" operand but if I type cast it to an int but then I also get the lowercase ASCII value for each letter and make it a constant to figure out which one goes first I could do it this way but there has to be an easier way to do this. Below I have pasted the entire program as to make it easier to understand the context of the function, the function in question is the very last one named "list_selection_sort". Any idea or comments would be much appreciated. Thanks, Jordan <code> void list_selection_sort(Node_ptr &a_list) { Node_ptr currNode; Node_ptr nextNode; Node_ptr lastNode; int itiems = 1; currNode = a_list; while(currNode ->ptr_to_next_node != NULL) { currNode = currNode ->ptr_to_next_node; itiems++; } lastNode = currNode; currNode = a_list; nextNode = currNode ->ptr_to_next_node; while (itiems > 0) { if(currNode -> word[0] > nextNode -> word[0]) { curr } else { lastNode = currNode; currNode = currNode ->ptr_to_next_node; nextNode = currNode ->ptr_to_next_node;} itiems--; } system("pause"); } <\code> |
From: Jordan B. <jor...@me...> - 2011-05-02 02:30:26
|
I have the following code and have ran it through the debugger several times and still can not nail why it is acting so funny. I am doing this for a work project and am getting pretty desperate at this point with the meeting coming up and I still can not get down these simple linked lists program. As you can see the program should add the following numbers to the list and change as specified by the calls to the functions in respect to their arguments, The program will compile but has an infinite loop at the del function I belove as the memory fails once it gets to that location. Also when displaying the list the first time it does not show the digit 1 as it should. Upon displaying the list a second time it then shows it. Any help would be much appreciated. #include <iostream> using namespace std; class linklist { private: struct node { int data; node *link; }*p; public: linklist(); void append( int num ); void first( int num ); void next( int c, int num ); void del( int num ); void display(); int count(); ~linklist(); }; linklist::linklist() { p=NULL; } void linklist::append(int num) { node *newNode = new node; node *nextNode = new node; if (p == NULL) { p = newNode; p ->data = num; p->link = NULL; } else newNode = new node; node * n = p; while(n -> link){n = n -> link;} n-> link = newNode; newNode -> data = num; newNode -> link = NULL; } void linklist::first(int num) { node * newNode; newNode = new node; newNode -> data = num; newNode -> link = p; p = newNode; } void linklist::next( int c, int num) { node *lastNode; node *currNode; node *nextNode; currNode = p; lastNode = currNode; nextNode = currNode -> link; while(c != 0) { lastNode = currNode; currNode = currNode -> link; nextNode = currNode -> link; c--; } node *newNode; newNode = new node; newNode -> data = num; currNode -> link = newNode; newNode -> link = nextNode; } void linklist::del( int num ) { node * lastNode; node * currNode; node * nextNode; currNode = p; lastNode = currNode; nextNode = currNode -> link; while(currNode != NULL) { if(currNode -> data == num) { lastNode -> link = nextNode; break; } else lastNode = currNode; currNode = currNode -> link; nextNode = currNode -> link; } cout << "Itiems not found" << endl; } void linklist::display() { node * a_node; a_node = p; while(a_node != NULL) { cout << a_node -> data << endl; a_node = a_node -> link; } } int linklist:: count () { int count =1; node *a_node; if(p == NULL) { return count; } else { a_node = p; while(a_node -> link != NULL) { count++; a_node = a_node -> link; } } return count;} linklist::~linklist() { node *q; if( p == NULL ) return; while( p != NULL ) { q = p->link; delete p; p = q; } } void main() { cout << "Name: COMP 1302 Homework Four" << endl; cout << "Christine Kikuchi" << endl; cout << "Purpose: A simple list that will create a list," << endl; cout << " count the number of its elements, " << endl; cout << " and tell if an item is on the list." << endl; cout << endl; linklist ll; cout<<"No. of elements = "<<ll.count(); ll.append(12); ll.append(13); ll.append(23); ll.append(43); ll.append(44); ll.append(50); ll.first(2); ll.first(1); ll.next(3,333); ll.next(6,666); ll.display(); cout<<"\nNo. of elements = "<<ll.count(); cout << endl; ll.del(333); ll.del(12); ll.del(98); cout<<"\nNo. of elements = "<<ll.count(); cout << endl; ll.display(); system("pause"); } |
From: Michal M. <mol...@se...> - 2011-05-01 22:10:29
|
Dne 1.5.2011 18:21, Jordan Burnam napsal(a): > void linklist::append(int num) > { > node * newNode; > > if(p =NULL) should be if(p==NULL) > { > p = new node; > p -> data = num; > p -> link = newNode; should be p->link = NULL; > } > else { newNode = new node; node* n = p; while (n->link) { n = n->link; } n->link = newNode; > newNode -> data = num; newNode -> link = NULL; } // else > } > void linklist::first(int num) > { > node *newNode; > newNode = new node; newNode -> data = num; newNode -> link = p; p = newNode; > } |
From: Jordan B. <jor...@me...> - 2011-05-01 16:21:43
|
Below is the program that I have and am trying to fill in the blanks to help me better understand pointers. I have added the code to the append function and the first function I believe this is right but want to make sure I am heading in the right direction. The function "first" should add the variable being passed do it to the first of the list and the function append should add the element at the end of the list. #include <iostream> using namespace std; class linklist { private: struct node { int data; node *link; }*p; public: linklist(); void append( int num ); void first( int num ); void next( int c, int num ); void del( int num ); void display(); int count(); ~linklist(); }; linklist::linklist() { p=NULL; } void linklist::append(int num) { node * newNode; if(p =NULL) { p = new node; p -> data = num; p -> link = newNode; } else newNode -> data = num; newNode -> link = new node; newNode = newNode-> link; } void linklist::first(int num) { node *newNode; newNode = new node; newNode -> data = p -> data; newNode -> link = p -> link; p=NULL; p = new node; p -> data = num; p -> link = newNode; *newNode = NULL; } void linklist::next( int c, int num) { //Add implementation code here } void linklist::del( int num ) { //Add implementation code here } void linklist::display() { //Add implementation code here } linklist::~linklist() { node *q; if( p == NULL ) return; while( p != NULL ) { q = p->link; delete p; p = q; } } void main() { linklist ll; cout<<"No. of elements = "<<ll.count(); ll.append(12); llappend(13); ll.append(23); ll.append(43); ll.append(44); ll.append(50); ll.first(2); llfirst(1); ll.next(3,333); ll.next(6,666); ll.display(); cout<<"\nNo. of elements = "<<ll.count(); ll.del(333); ll.del(12); ll.del(98); cout<<"\nNo. of elements = "<<ll.count(); } |
From: Michal M. <mol...@se...> - 2011-05-01 00:07:54
|
Dne 30.4.2011 18:30, Jordan Burnam napsal(a): > Here is my code thus far. I need a algorithm for the function that sorts > the list( it is the very last function). I know there is a simple way to > do this since it is a linked list. Any help I would gratefully welcome. You can use any sorting algorithm that does not need random access to elements, like bubble sort, which is easy to implement. Real applications which needs to sort linked list in place would use probably merge sort. However note that copying it to array, sorting it and copying it back may be actually much faster anyway. |
From: Jordan B. <jor...@me...> - 2011-04-30 16:30:52
|
Here is my code thus far. I need a algorithm for the function that sorts the list( it is the very last function). I know there is a simple way to do this since it is a linked list. Any help I would gratefully welcome. #include <iostream> #include <cstdlib> #include <cstring> using namespace std; const int MAX_WORD_LENGTH = 80; /* definition of a node */ struct Node; typedef Node *Node_ptr; struct Node { char word[MAX_WORD_LENGTH]; Node_ptr ptr_to_next_node; }; /* Function to assign a linked list to "a_node" */ void assign_list(Node_ptr &a_list); /* Function to assign a new dynamic node variable to "a_node" */ void assign_new_node(Node_ptr &a_node); /* Function to print the strings in the list "a_node" */ void print_list(Node_ptr a_node); void add_after(Node_ptr &list, char a_word[], char word_after[]); //This function inserts a node containing "word_after" in the linked list "list", after the first occurrence of a node containing "a_word". If "list" does not contain such a node, the function leaves it unchanged. void delete_node(Node_ptr &a_list, char a_word[]); //This function deletes the first node in "a_list" which contains "a_word" |
From: Jordan B. <jor...@me...> - 2011-04-30 16:23:58
|
Below is the code I have thus far for my program. I am now in need of a method to sort this linked list alphabetically. The functioning that will handle this is "list_selection_sort()". Does any one have an Idea. I know that I could do it by copying each word from the linked list and sort them in an array and use a loop to link them all together but that is copying too much and using too many of the computers resources. I know there is a simple algortihm for this since the list is a linked list. #include <iostream> #include <cstdlib> #include <cstring> using namespace std; const int MAX_WORD_LENGTH = 80; /* definition of a node */ struct Node; typedef Node *Node_ptr; struct Node { char word[MAX_WORD_LENGTH]; Node_ptr ptr_to_next_node; }; /* Function to assign a linked list to "a_node" */ void assign_list(Node_ptr &a_list); /* Function to assign a new dynamic node variable to "a_node" */ void assign_new_node(Node_ptr &a_node); /* Function to print the strings in the list "a_node" */ void print_list(Node_ptr a_node); void add_after(Node_ptr &list, char a_word[], char word_after[]); //This function inserts a node containing "word_after" in the linked list "list", after the first occurrence of a node containing "a_word". If "list" does not contain such a node, the function leaves it unchanged. void delete_node(Node_ptr &a_list, char a_word[]); //This function deletes the first node in "a_list" which contains "a_word" |
From: Michal M. <mol...@se...> - 2011-04-26 20:19:44
|
if(strcmp(word_after,currNode->word)) should be if(strcmp(word_after,currNode->word) == 0) |
From: Per W. <pw...@ia...> - 2011-04-26 20:14:36
|
Don't you have access to a debugger? With a debugger, you can single-step the code and see yourself where the program does something that you didn't expect. You seem to have fixed the error where you used one of the parameters to the insert_after() both to locate where to insert and as the new string to insert. When your code "always" (it doesn't really) inserts the word directly after the first word in the list (which isn't true really) then it must be quite reasonable to suspect the code that performs the string comparison. However, you haven't read the manual for strcmp(). if(strcmp(word_after,currNode->word)) strcmp will return three different alternatives: less than zero equal to zero greater than zero Quite logical since the two strings you send in as parameters may be smaller than, equal to, or larger than each other. Your goal is to find a match, i.e. equal. If you google "man strcmp" you would notice that strcmp() returns zero when the two strings are matching. Your if statement on the other hand gets activated if strcmp() returns non-zero, i.e. that the word is greater than or smaller than the word you are looking for. But a more interesting question here - besides your incorrect use of the result from strcmp() is why you mix C and C++ like you do. You are using C++ constructs to read input and print output. But you are not using the C++ string data type for text strings. Instead, you are using the character arrays available in C. What happens if you read in a longer word than your fixed-size character arrays can store? Your previous code used strncpy() - but that one will not zero-terminate strings that are too big to fit. Now you have strcpy() that don't care at all about available space. And the input from cin will not know how many characters that fits. /pwm On Tue, 26 Apr 2011, Jordan Burnam wrote: > Hi everyone, > > I have the following program that I have created and am trying > to get this work correctly. The purpose of this program is to make a > litst from the users input then allow the user to add a word after a > word in the list. So far this list only adds the word after the first > word each time. I have looked at it and ad peers online to view it and > have advised me that I have used a variable twice and that is what is > causing this but I am not catching it. I am confident that it is in the > function "add_after" as this is the function called to add after a word. > I have hand traced a couple of times but with no avail. Could somone > please point out my logic error. > > <code> > #include <iostream> > #include <cstdlib> > #include <cstring> > using namespace std; > const int MAX_WORD_LENGTH = 80; > /* definition of a node */ > struct Node; > typedef Node *Node_ptr; > struct Node > { > char word[MAX_WORD_LENGTH]; > Node_ptr ptr_to_next_node; > }; > /* Function to assign a linked list to "a_node" */ > void assign_list(Node_ptr &a_list); > /* Function to assign a new dynamic node variable to "a_node" */ > void assign_new_node(Node_ptr &a_node); > /* Function to print the strings in the list "a_node" */ > void print_list(Node_ptr a_node); > ã > void add_after(Node_ptr &list, char a_word[], char word_after[]); > //This function inserts a node containing "word_after" in the linked list "list", after the first occurrence of a node containing "a_word". If "list" does not contain such a node, the function leaves it unchanged. > //***************************************************** > void main() > { > char word_a[MAX_WORD_LENGTH]; > char aword[MAX_WORD_LENGTH]; > Node_ptr my_list = NULL; > assign_list(my_list); > cout << "\nTHE LIST IS NOW:\n"; > print_list(my_list); > cout << "After which word would you like to add a word?:"; > cin >> word_a; > cout << "What word would you like to add after that word?:"; > cin >> aword; > add_after(my_list,aword, word_a); > cout << "The list is now:"<< endl; > print_list(my_list); > system("pause"); > ã > ã > ã > } > //***************************************************** > /* DEFINITION OF FUNCTION "assign_list" */ > void assign_list(Node_ptr &a_list) > { > Node_ptr current_node, last_node; > assign_new_node(a_list); > cout << "Enter first word (or '.' to end list): "; > cin >> a_list->word; > if (!strcmp(".",a_list->word)) > { > delete a_list; > a_list = NULL; > } > current_node = a_list; > while (current_node != NULL) > { > assign_new_node(last_node); > cout << "Enter next word (or '.' to end list): "; > cin >> last_node->word; > if (!strcmp(".",last_node->word)) > { > delete last_node; > last_node = NULL; > } > current_node->ptr_to_next_node = last_node; > current_node = last_node; > } > } > /* END OF FUNCTION DEFINITION */ > /* DEFINITION OF FUNCTION "assign_new_node" */ > void assign_new_node(Node_ptr &a_node) > { > a_node = new Node; > if (a_node == NULL) > { > cout << "sorry - no more memory\n"; > exit(1); > } > } > //***************************************************** > /* DEFINITION OF FUNCTION "print_list" */ > void print_list(Node_ptr a_node) > { > while (a_node != NULL) > { > cout << a_node->word << " "; > a_node = a_node->ptr_to_next_node; > } > } > //***************************************************** > void add_after(Node_ptr &list, char a_word[], char word_after[]) > { > Node_ptr currNode; > Node_ptr newNode; > Node_ptr nextNode; > currNode = list; > while(currNode ->ptr_to_next_node != NULL) > { > if(strcmp(word_after,currNode->word)) > { > assign_new_node(newNode); > nextNode = currNode ->ptr_to_next_node; > currNode ->ptr_to_next_node = newNode; > newNode ->ptr_to_next_node = nextNode; > strcpy (newNode ->word,a_word); > break; > } > else > currNode = currNode -> ptr_to_next_node; > } > } > </code> |
From: Jordan B. <jor...@me...> - 2011-04-26 19:02:31
|
Hi everyone, I have the following program that I have created and am trying to get this work correctly. The purpose of this program is to make a litst from the users input then allow the user to add a word after a word in the list. So far this list only adds the word after the first word each time. I have looked at it and ad peers online to view it and have advised me that I have used a variable twice and that is what is causing this but I am not catching it. I am confident that it is in the function "add_after" as this is the function called to add after a word. I have hand traced a couple of times but with no avail. Could somone please point out my logic error. <code> #include <iostream> #include <cstdlib> #include <cstring> using namespace std; const int MAX_WORD_LENGTH = 80; /* definition of a node */ struct Node; typedef Node *Node_ptr; struct Node { char word[MAX_WORD_LENGTH]; Node_ptr ptr_to_next_node; }; /* Function to assign a linked list to "a_node" */ void assign_list(Node_ptr &a_list); /* Function to assign a new dynamic node variable to "a_node" */ void assign_new_node(Node_ptr &a_node); /* Function to print the strings in the list "a_node" */ void print_list(Node_ptr a_node); void add_after(Node_ptr &list, char a_word[], char word_after[]); //This function inserts a node containing "word_after" in the linked list "list", after the first occurrence of a node containing "a_word". If "list" does not contain such a node, the function leaves it unchanged. //***************************************************** void main() { char word_a[MAX_WORD_LENGTH]; char aword[MAX_WORD_LENGTH]; Node_ptr my_list = NULL; assign_list(my_list); cout << "\nTHE LIST IS NOW:\n"; print_list(my_list); cout << "After which word would you like to add a word?:"; cin >> word_a; cout << "What word would you like to add after that word?:"; cin >> aword; add_after(my_list,aword, word_a); cout << "The list is now:"<< endl; print_list(my_list); system("pause"); } //***************************************************** /* DEFINITION OF FUNCTION "assign_list" */ void assign_list(Node_ptr &a_list) { Node_ptr current_node, last_node; assign_new_node(a_list); cout << "Enter first word (or '.' to end list): "; cin >> a_list->word; if (!strcmp(".",a_list->word)) { delete a_list; a_list = NULL; } current_node = a_list; while (current_node != NULL) { assign_new_node(last_node); cout << "Enter next word (or '.' to end list): "; cin >> last_node->word; if (!strcmp(".",last_node->word)) { delete last_node; last_node = NULL; } current_node->ptr_to_next_node = last_node; current_node = last_node; } } /* END OF FUNCTION DEFINITION */ /* DEFINITION OF FUNCTION "assign_new_node" */ void assign_new_node(Node_ptr &a_node) { a_node = new Node; if (a_node == NULL) { cout << "sorry - no more memory\n"; exit(1); } } //***************************************************** /* DEFINITION OF FUNCTION "print_list" */ void print_list(Node_ptr a_node) { while (a_node != NULL) { cout << a_node->word << " "; a_node = a_node->ptr_to_next_node; } } //***************************************************** void add_after(Node_ptr &list, char a_word[], char word_after[]) { Node_ptr currNode; Node_ptr newNode; Node_ptr nextNode; currNode = list; while(currNode ->ptr_to_next_node != NULL) { if(strcmp(word_after,currNode->word)) { assign_new_node(newNode); nextNode = currNode ->ptr_to_next_node; currNode ->ptr_to_next_node = newNode; newNode ->ptr_to_next_node = nextNode; strcpy (newNode ->word,a_word); break; } else currNode = currNode -> ptr_to_next_node; } } </code> |
From: João M. R. S. T. <ta...@fe...> - 2011-04-26 17:03:39
|
---------------------------------------------------------------------------- ------------------------------------------------------- International ECCOMAS Thematic Conference VipIMAGE 2011 - III ECCOMAS THEMATIC CONFERENCE ON COMPUTATIONAL VISION AND MEDICAL IMAGE PROCESSING 12-14th October 2011, Olhão, Algarve, Portugal <http://www.fe.up.pt/~vipimage> www.fe.up.pt/~vipimage LAST POSTPONEMENT We would appreciate if you could distribute this information by your colleagues and co-workers. ---------------------------------------------------------------------------- ------------------------------------------------------- Dear Colleague, Due to several requests, we have postponed the submission deadline to May 15, 2011. We would like to invite you to share your work in the International Conference VipIMAGE 2011 - III ECCOMAS THEMATIC CONFERENCE ON COMPUTATIONAL VISION AND MEDICAL IMAGE PROCESSING that will be held in Real Marina Hotel & Spa, Olhão, Algarve, Portugal, on October 12-14, 2011. Possible Topics (not limited to) - Signal and Image Processing - Computational Vision - Medical Imaging - Physics of Medical Imaging - Tracking and Analysis of Movement - Simulation and Modeling - Image Acquisition - Shape Reconstruction - Objects Segmentation, Matching, Simulation - Data Interpolation, Registration, Acquisition and Compression - 3D Vision - Virtual Reality - Software Development for Image Processing and Analysis - Computer Aided Diagnosis, Surgery, Therapy, and Treatment - Computational Bioimaging and Visualization - Telemedicine Systems and their Applications Invited Lecturers - Armando J. Pinho - University of Aveiro, Portugal - Irene M. Gamba - The University of Texas at Austin, USA - Marc Pollefeys - ETH Zurich, Switzerland - Marc Thiriet - Universite Pierre et Marie Curie (Paris VI), France - Xavier Roca Marvà - Autonomous University of Barcelona, Spain - Stan Sclaroff - Boston University, USA Thematic Sessions - Simultaneous MR-PET imaging - Satellite image analysis for environmental risk assessment - Dental Imaging and Processing Techniques - Digital Mammography - Imaging of Biological Flows: trends and challenges - Imaging techniques applied to soft tissue Biomechanics Publications The proceedings book will be published by the Taylor & Francis Group and indexed by Thomson Reuters Conference Proceedings Citation Index, IET Inspect and Elsevier Scopus. A book with 20 invited works from the best ones presented in VipIMAGE2011 (extended versions) will be published by Springer. A special issue of The International Journal for Numerical Methods in Biomedical Engineering dedicated to VipIMAGE 2011 (with extended versions of 12 selected works), will be published by John Wiley & Sons. Important dates - Deadline for Extended Abstracts: 15th May 2011 (postponed) - Authors Notification: 31st May 2011 (postponed) - Deadline for Full Papers: 30th June 2011 Awards "best paper award" and "best student paper award" are going to be given to the author(s) of two papers presented at the conference, selected by the Organizing Committee based on the best combined marks from the Scientific Committee and Session Chairpersons. We are looking forward to see you in Algarve next October. Kind regards, João Manuel R. S. Tavares Renato Natal Jorge (conference co-chairs) PS. For further details please see the conference website at: <http://www.fe.up.pt/~vipimage> www.fe.up.pt/~vipimage |
From: Michal M. <mol...@se...> - 2011-04-25 23:58:52
|
There are two additional errors: 1) As already pointed out by Per, you are using a_word instead of word_after in the condition, so the line: if(currNode -> word == a_word) should be: if (strcmp(currNode -> word, word_after) == 0) 2) The infinite loop is because when you found the word you do not change the currNode so the while(currNode != NULL) never becames true. Using break is correct solution you just have to put it right before the else part: if (strcmp(currNode -> word, word_after) == 0) { assign_new_node(newNode); nextNode = currNode ->ptr_to_next_node; currNode ->ptr_to_next_node = newNode; newNode ->ptr_to_next_node = nextNode; strncpy(newNode->word, a_word, MAX_WORD_LENGTH); break; // HERE } else currNode = currNode -> ptr_to_next_node; } (You can as well do currNode = NULL; instead of the break or use return in this case.) Dne 25.4.2011 2:10, jordanburnam1990 napsal(a): > Now I get an infinite loop when using the compare string functions > for the if statement in add_after any ideas? > > Sent from my iPhone > > On Apr 24, 2011, at 4:51 PM, Michal Molhanec<mol...@se...> > wrote: > >> Dne 24.4.2011 20:23, Jordan Burnam napsal(a): >>> if(currNode -> word == a_word) >> >> You cannot compare strings with ==, you'll have to use strcmp() >> function like it is already used inside the assign_list() >> function. >> > > I saw why I had the infinite loop cause it traversed through the > dynamic memory till it found the end which can take a while. So I > added a break statement after the if statement and that has solved > it. But now it adds the name to the wrong place in the list each > time. I know it's a simple logic error but I just can't seem to pin > point it. |
From: Per W. <pw...@ia...> - 2011-04-25 07:04:12
|
Note that your function is using the same word twice in the code - it isn't bothering about the other word. And also - you claim it should insert the new word after the "first" match - but if the function doesn't return after a match, it will insert the new word after every match. /pwm On Sun, 24 Apr 2011, jordanburnam1990 wrote: > Now I get an infinite loop when using the compare string functions for the if statement in add_after any ideas? > > Sent from my iPhone > > On Apr 24, 2011, at 4:51 PM, Michal Molhanec <mol...@se...> wrote: > > > Dne 24.4.2011 20:23, Jordan Burnam napsal(a): > >> if(currNode -> word == a_word) > > > > You cannot compare strings with ==, you'll have to use strcmp() function like it is already used inside the assign_list() function. > > > > ------------------------------------------------------------------------------ > Fulfilling the Lean Software Promise > Lean software platforms are now widely adopted and the benefits have been > demonstrated beyond question. Learn why your peers are replacing JEE > containers with lightweight application servers - and what you can gain > from the move. http://p.sf.net/sfu/vmware-sfemails > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
From: Reid T. <rei...@at...> - 2011-04-25 03:26:50
|
On 4/24/2011 2:23 PM, Jordan Burnam wrote: > if(currNode -> word == a_word) you can't compare strings this way man or google strcmp and friends |
From: jordanburnam1990 <jor...@me...> - 2011-04-25 00:10:44
|
Now I get an infinite loop when using the compare string functions for the if statement in add_after any ideas? Sent from my iPhone On Apr 24, 2011, at 4:51 PM, Michal Molhanec <mol...@se...> wrote: > Dne 24.4.2011 20:23, Jordan Burnam napsal(a): >> if(currNode -> word == a_word) > > You cannot compare strings with ==, you'll have to use strcmp() function like it is already used inside the assign_list() function. > |
From: Michal M. <mol...@se...> - 2011-04-24 20:51:32
|
Dne 24.4.2011 20:23, Jordan Burnam napsal(a): > if(currNode -> word == a_word) You cannot compare strings with ==, you'll have to use strcmp() function like it is already used inside the assign_list() function. |
From: Jordan B. <jor...@me...> - 2011-04-24 18:23:46
|
My teacher has given us the following code, within this code I have added the function "void add_after" and am trying to get it to work I do not get an error with this program. It will run but it will not add the word after. I think once you review the code it should be self explanatory: <code> #include <iostream> #include <cstdlib> #include <cstring> using namespace std; const int MAX_WORD_LENGTH = 80; /* definition of a node */ struct Node; typedef Node *Node_ptr; struct Node { char word[MAX_WORD_LENGTH]; Node_ptr ptr_to_next_node; }; /* Function to assign a linked list to "a_node" */ void assign_list(Node_ptr &a_list); /* Function to assign a new dynamic node variable to "a_node" */ void assign_new_node(Node_ptr &a_node); /* Function to print the strings in the list "a_node" */ void print_list(Node_ptr a_node); void add_after(Node_ptr &list, char a_word[], char word_after[]); //This function inserts a node containing "word_after" in the linked list "list", after the first occurrence of a node containing "a_word". If "list" does not contain such a node, the function leaves it unchanged. //***************************************************** void main() { char word_a[MAX_WORD_LENGTH]; char aword[MAX_WORD_LENGTH]; Node_ptr my_list = NULL; assign_list(my_list); cout << "\nTHE LIST IS NOW:\n"; print_list(my_list); cout << "After which word would you like to add a word?:"; cin >> word_a; cout << "What word would you like to add after that word?:"; cin >> aword; add_after(my_list,aword, word_a); cout << "The list is now:"<< endl; print_list(my_list); } //***************************************************** /* DEFINITION OF FUNCTION "assign_list" */ void assign_list(Node_ptr &a_list) { Node_ptr current_node, last_node; assign_new_node(a_list); cout << "Enter first word (or '.' to end list): "; cin >> a_list->word; if (!strcmp(".",a_list->word)) { delete a_list; a_list = NULL; } current_node = a_list; while (current_node != NULL) { assign_new_node(last_node); cout << "Enter next word (or '.' to end list): "; cin >> last_node->word; if (!strcmp(".",last_node->word)) { delete last_node; last_node = NULL; } current_node->ptr_to_next_node = last_node; current_node = last_node; } } /* END OF FUNCTION DEFINITION */ /* DEFINITION OF FUNCTION "assign_new_node" */ void assign_new_node(Node_ptr &a_node) { a_node = new Node; if (a_node == NULL) { cout << "sorry - no more memory\n"; exit(1); } } //***************************************************** /* DEFINITION OF FUNCTION "print_list" */ void print_list(Node_ptr a_node) { while (a_node != NULL) { cout << a_node->word << " "; a_node = a_node->ptr_to_next_node; } } //***************************************************** void add_after(Node_ptr &list, char a_word[], char word_after[]) { Node_ptr currNode; Node_ptr newNode; Node_ptr nextNode; currNode = list; while(currNode != NULL) { if(currNode -> word == a_word) { assign_new_node(newNode); nextNode = currNode ->ptr_to_next_node; currNode ->ptr_to_next_node = newNode; newNode ->ptr_to_next_node = nextNode; strncpy(newNode->word, a_word, MAX_WORD_LENGTH); } else currNode = currNode -> ptr_to_next_node; } } </code> |