Rosetta Code talk:Add a Task: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 11: Line 11:
: Suggest creating a "what to expect" section, noting common variations and the like, noting that the task author is likely to be surprised by creative (but not necessarilly inappropriate) solutions. "other algorithms" would fall under that, pretty much as a single bullet point. --[[User:Short Circuit|Michael Mol]] 16:24, 8 October 2010 (UTC)
: Suggest creating a "what to expect" section, noting common variations and the like, noting that the task author is likely to be surprised by creative (but not necessarilly inappropriate) solutions. "other algorithms" would fall under that, pretty much as a single bullet point. --[[User:Short Circuit|Michael Mol]] 16:24, 8 October 2010 (UTC)


== Semantic annotations? ==
== what's doubly list ?? ==


Doubly linked list is a complex type of linked list in which a node contains a pointer to the previous as well as the next node in the sequence. Therefore, in a doubly linked list, a node consists of three parts: node data, pointer to the next node in sequence (next pointer) , pointer to the previous node (previous pointer)
Could we get a bit more on semantic annotations? I am not sure if I have ever seen them before here. And the illustrative example does not help me since, when I currently go to [[Delegates|the referenced page]] it does not seem to have any examples of semantic annotations (but it does have a lot of <code>::</code> which makes checking for what I think I am looking for frustrating). --[[User:Rdm|Rdm]] 21:08, 9 November 2010 (UTC)
: Hm. I'll try to explain it better here, so the page body can be updated in a more clear fashion after it's been vetted and I'm sure I really know what I'm talking about. (I'm not entirely clear on it myself, I just know a couple ways the feature can be used/abused to RC's benefit.) Semantic properties take the form of ''''<nowiki>[[property name::this page's relationship to that property.]]</nowiki>'''. I don't know what happened to the semantic notations on the delegate page. It's possible I never committed my changes to that page while I was writing this one. For a list of current properties and their usage, check out [[Special:Properties]]. It might also help to look at [[smw:Help:Properties and types]]. --[[User:Short Circuit|Michael Mol]] 21:16, 9 November 2010 (UTC)
:: Ok, if I understand right: properties are like regular wikilinks but with an (invisible) prefix for consumption by computer programs. They are typically used in templates. --[[User:Rdm|Rdm]] 21:25, 9 November 2010 (UTC)
::: At a first pass, yes. Note that the prefix and suffix become related, as well as the page the link is created on. Additionally, it's possible (and desirable in a number of places on RC) to create the prefix/suffix/page association without a visisble component. Finally, the wiki software itself consumes those associations, allowing us to use [[smw:Help:Semantic search|semantic searches]] to do interesting things. (Such as dynamically creating task page and example listings based on task properties, or (eventually) replacing MultiCategorySearch as the mechanism we use for the 'unimplemented in X' pages, and, even farther, 'unimplemented using Y' pages where Y is some concept (language, paradigm, library or other tool) as desired.) --[[User:Short Circuit|Michael Mol]] 21:35, 9 November 2010 (UTC)
:::The way I've seen properties is sort of like ternary categories. With regular categories, you're in or you're out. With properties, not only are you in or out, but you also have a value within it. So a task is in the "Implemented in language" proerty once it has examples, but it's also "implemented in" different languages. So you can go to the [[Property:Implemented in language|Implemented in language property page]] and see all the pages on the left which are "implemented in" something (just like a category). On the right you see the values given for each of those pages, which are the languages that they are implemented in.


Generally, doubly linked list consumes more space for every node and therefore, causes more expansive basic operations such as insertion and deletion. However, we can easily manipulate the elements of the list since the list maintains pointers in both the directions (forward and backward).
:::Just for another way to think about it, maybe we can say that Cateories are DB tables where the keys are the page names. Then Properties would be tables where the keys are the page name and an additional value. --[[User:Mwn3d|Mwn3d]] 22:27, 9 November 2010 (UTC)

In the first element of the list that is i.e. 13 stored at address 1. The head pointer points to the starting address 1. Since this is the first element being added to the list therefore the prev of the list contains null. The next node of the list resides at address 4 therefore the first node contains 4 in its next pointer.

We can traverse the list in this way until we find any node containing null or -1 in its next part.


== C++ linkedlist implementation by me ==
== C++ linkedlist implementation by me ==

Revision as of 01:05, 1 June 2019

I've been asked numerous times about how to create a task. I've never had a good answer. This page represents a draft of my best idea of it.

  • Please examine, edit, refine, review and debate it.
  • Go through our existing set of tasks and use this page as a benchmark for gauging task quality. If the task seems of good quality (i.e. matches the prerequisites), despite not matching this page well, then the page likely requires modification.
  • Build a list (somewhere, anywhere, wikicode or semantic query, be as practical or creative as necessary) where we can see our existing task set and see how well the task description matches this page. --Michael Mol 17:41, 20 September 2010 (UTC)

First implementation

One of the key aspects of Software Engineering is to avoid reinventing the wheel. Reusability is always preferred.

Other Algorithms

There needs to be a mention of the use of 'other' algorithms when the task allows - for example using regexps instead of an example using string search; or some other technique when brute-force search is the current solution method. We usually welcome them -sometimes on their own - other times in addition to other methods of solution. (Various Knapsack problem solutions have better methods than brute-force search for example). --Paddy3118 15:59, 8 October 2010 (UTC)

Suggest creating a "what to expect" section, noting common variations and the like, noting that the task author is likely to be surprised by creative (but not necessarilly inappropriate) solutions. "other algorithms" would fall under that, pretty much as a single bullet point. --Michael Mol 16:24, 8 October 2010 (UTC)

what's doubly list ??

Doubly linked list is a complex type of linked list in which a node contains a pointer to the previous as well as the next node in the sequence. Therefore, in a doubly linked list, a node consists of three parts: node data, pointer to the next node in sequence (next pointer) , pointer to the previous node (previous pointer)

Generally, doubly linked list consumes more space for every node and therefore, causes more expansive basic operations such as insertion and deletion. However, we can easily manipulate the elements of the list since the list maintains pointers in both the directions (forward and backward).

In the first element of the list that is i.e. 13 stored at address 1. The head pointer points to the starting address 1. Since this is the first element being added to the list therefore the prev of the list contains null. The next node of the list resides at address 4 therefore the first node contains 4 in its next pointer.

We can traverse the list in this way until we find any node containing null or -1 in its next part.

C++ linkedlist implementation by me

== //- University of Delhi //- by Manish Natraj shohbby // - c++ list

   #include <iostream>
   #include  <cstdlib>
   using namespace std;
   template <class T>
   struct node
   {
       T data;
       node * next;
       node * pre;
   };
   template <class T>
   class list
   {
   public:
       class Iterator
       {
       public:
           node<T>* it ;
           Iterator()
           {
               it = NULL;
           }
           void operator ++()
           {
               if(it!=NULL)
                   it = it->next;
           }
           void operator ++(int)
           {
               if(it!=NULL)
                   it = it->next;
           }
           void operator --()
           {
               if(it!=NULL)
                   it = it->pre;
           }
           void operator --(int)
           {
               if(it!=NULL)
                   it = it->pre;
           }
           T& operator * ()
           {
               return it->data;
           }
           bool operator==(const Iterator * x)
           {
               return (it==x.it);
           }
       };
       list()
       {
           node<T> * dummy = new node<T> ;
           head = tail = dummy;
           head->pre =NULL;
       }
       list(T value, int size)
       {
           node<T> * n ;
           node<T> * dummy = new node<T> ;
           head = tail = dummy;
           head->pre =NULL;
           for(int i=0 ; i<size ; i++)
           {
               n = new node<T>;
               n->data = value ;
               n->next = head;
               head->pre = n;
               head = n ;
           }
       }
       ~list()
       {
           node<T> * temp ;
           while (head!=tail)
           {
               temp = head ;
               head = head->next;
               delete temp;
           }
           delete tail;
       }
       void print()
       {
           node<T> * temp = head ;
           while (temp!=tail)
           {
               cout<<temp->data<<"  ";
               temp = temp->next;
           }
       }
       int size()
       {
           int count = 0;
           node<T> * temp = head ;
           while (temp!=tail)
           {
               count++;
               temp = temp->next;
           }
           return count ;
       }
       void insert(T value, Iterator p)
       {
           node<T> * temp = head ;
           node<T> * temp1 ;
           node<T> * n = new node<T> ;
           n->data = value;
           if(head == p.it)
           {
               n->next = head;
               n->pre = NULL;
               head->pre=n;
               head = n;
               return;
           }
           if(tail == p.it)
           {
               tail->data = value;
               tail->next = n;
               n->pre= tail;
               tail = n;
               return;
           }
           while (temp!=p.it)
           {
               temp1 = temp ;
               temp = temp->next;
               if(temp==tail)
               {
                   return;
               }
           }
           temp1->next = n ;
           n->pre= temp1;
           n->next = temp ;
           temp->pre=n;
       }
       void erase(Iterator p)
       {
           node<T> * temp = head ;
           node<T> * temp1 ;
           if(p.it == tail )
           {
               cout<<" no location found "<<endl;
               return;
           }
           else if (p.it == head )
           {
               head = head->next;
               head->pre = NULL ;
               delete temp;
               return;
           }
           while (temp!=p.it)
           {
               temp1 = temp ;
               temp = temp->next;
               if(temp == tail)
               {
                   cout<<" no location found "<<endl;
                   return;
               }
           }
           temp1->next = temp->next;
           temp->next->pre = temp1;
           delete temp;
       }
       list<T>& operator= (const list<T> & l)
       {
           node<T> * temp ;
           node<T> * temp2 = l.head ;
           while (head!=tail)
           {
               temp = head ;
               head = head->next;
               delete temp;
           }
           temp2 = l.tail->pre;
           while (temp2!=NULL)
           {
               insert(temp2->data, begin());
               temp2=temp2->pre;
           }
       }
       Iterator begin ()
       {
           Iterator i ;
           i.it =  head ;
           return i ;
       }
       Iterator end()
       {
           Iterator i ;
           i.it =  tail ;
           return i ;
       }
   private:
       node<T> * head ;
       node<T> * tail ;
   };


   int main()
   {
       list <int> l(3,5);
       list <int> l2(2,4);
       l.print();
       cout<<endl << "size = " << l.size();
       list<int>::Iterator it =  l.begin();
       ++it;
       l.insert(9,it);
       cout << " data = "<< *it << endl ;
       it=l.end();
       l.insert(4,it);
       cout << "data = "<< *it << endl ;
       cout<<endl;
       l.print();
       it=l.end();
       l.insert(7,it);
       cout<<endl;
       cout << " data = "<< *it << endl ;
       l.print();
       it=l.begin();
       l.erase(it);
       cout<<endl;
       l.print();
       it=l.begin();
       it++;
       l.erase(it);
       cout<<endl;
       l.print();
       l2 = l;
       cout<<endl;
       l2.print();
       return 0;
   }
==