Search Results

Search found 33882 results on 1356 pages for 'singly linked list'.

Page 1/1356 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Implementing Linked Lists in C#

    - by nijhawan.saurabh
    Why? The question is why you need Linked Lists and why it is the foundation of any Abstract Data Structure. Take any of the Data Structures - Stacks, Queues, Heaps, Trees; there are two ways to go about implementing them - Using Arrays Using Linked Lists Now you use Arrays when you know about the size of the Nodes in the list at Compile time and Linked Lists are helpful where you are free to add as many Nodes to the List as required at Runtime.   How? Now, let's see how we go about implementing a Simple Linked List in C#. Note: We'd be dealing with singly linked list for time being, there's also another version of linked lists - the Doubly Linked List which maintains two pointers (NEXT and BEFORE).   Class Diagram Let's see the Class Diagram first:     Code     1 // -----------------------------------------------------------------------     2 // <copyright file="Node.cs" company="">     3 // TODO: Update copyright text.     4 // </copyright>     5 // -----------------------------------------------------------------------     6      7 namespace CSharpAlgorithmsAndDS     8 {     9     using System;    10     using System.Collections.Generic;    11     using System.Linq;    12     using System.Text;    13     14     /// <summary>    15     /// TODO: Update summary.    16     /// </summary>    17     public class Node    18     {    19         public Object data { get; set; }    20     21         public Node Next { get; set; }    22     }    23 }    24         1 // -----------------------------------------------------------------------     2 // <copyright file="LinkedList.cs" company="">     3 // TODO: Update copyright text.     4 // </copyright>     5 // -----------------------------------------------------------------------     6      7 namespace CSharpAlgorithmsAndDS     8 {     9     using System;    10     using System.Collections.Generic;    11     using System.Linq;    12     using System.Text;    13     14     /// <summary>    15     /// TODO: Update summary.    16     /// </summary>    17     public class LinkedList    18     {    19         private Node Head;    20     21         public void AddNode(Node n)    22         {    23             n.Next = this.Head;    24             this.Head = n;    25     26         }    27     28         public void printNodes()    29         {    30     31             while (Head!=null)    32             {    33                 Console.WriteLine(Head.data);    34                 Head = Head.Next;    35     36             }    37     38         }    39     }    40 }    41          1 using System;     2 using System.Collections.Generic;     3 using System.Linq;     4 using System.Text;     5      6 namespace CSharpAlgorithmsAndDS     7 {     8     class Program     9     {    10         static void Main(string[] args)    11         {    12             LinkedList ll = new LinkedList();    13             Node A = new Node();    14             A.data = "A";    15     16             Node B = new Node();    17             B.data = "B";    18     19             Node C = new Node();    20             C.data = "C";    21             ll.AddNode(A);    22             ll.AddNode(B);    23             ll.AddNode(C);    24     25             ll.printNodes();    26         }    27     }    28 }    29        Final Words This is just a start, I will add more posts on Linked List covering more operations like Delete etc. and will also explore Doubly Linked List / Implementing Stacks/ Heaps/ Trees / Queues and what not using Linked Lists.   Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}

    Read the article

  • Truly understand the threshold for document set in document library in SharePoint

    - by ybbest
    Recently, I am working on an issue with threshold. The problem is that when the user navigates to a view of the document library, it displays the error message “list view threshold is exceeded”. However, in the view, it has no data. The list view threshold limit is 5000 by default for the non-admin user. This limit is not the number of items returned by your query; it is the total number of items the database needs to read to calculate the returned result set. So although the view does not return any result but to calculate the result (no data to show), it needs to access more than 5000 items in the database. To fix the issue, you need to create an index for the column that you use in the filter for the view. Let’s look at the problem in details. You can download a solution to replicate this issue here. 1. Go to Central Admin ==> Web Application Management ==>General Settings==> Click on Resource Throttling 2. Change the list view threshold in web application from 5000 to 2000 so that I can show the problem without loading more than 5000 items into the list. FROM TO 3. Go to the page that displays the approved view of the Loan application document set. It displays the message as shown below although I do not have any data returned for this view. 4. To get around this, you need to create an index column. Go to list settings and click on the Index columns. 5. Click on the “Create a new index” link. 6. Select the LoanStatus field as I use this filed as the filter to create the view. 7. After the index is created now I can access the approved view, as you can see it does not return any data. Notes: List View Threshold: Specify the maximum number of items that a database operation can involve at one time. Operations that exceed this limit are prohibited. References: SharePoint lists V: Techniques for managing large lists Manage large SharePoint lists for better performance http://blogs.technet.com/b/speschka/archive/2009/10/27/working-with-large-lists-in-sharepoint-2010-list-throttling.aspx

    Read the article

  • Linked List is now Patented?

    - by John Isaiah Carmona
    Linked list Ming-Jen Wang Patent number: 7028023 Filing date: Sep 26, 2002 Issue date: Apr 11, 2006 Application number: 10/260,471 A computerized list is provided with auxiliary pointers for traversing the list in different sequences. One or more auxiliary pointers enable a fast, sequential traversal of the list with a minimum of computational time. Such lists may be used in any application where lists may be reordered for various purposes. Does this mean that I need to acquire permission before using a linked list in my codes? What about the codes I write from my previous apps that uses a linked list? What about the framework that implements the linked list?

    Read the article

  • SEO: Nested List vs List, Split Over Divs vs Definition List

    - by Jon P
    From an SEO perspective which, if any, is better: Option 1: Nested lists with h2 tags <ul id="mainpoints"> <li><h2>Powerful Analysis</h2> <ul> <li>Charting and indicators</li> <li>Daily trading signals</li> <li>Company health checks</li> </ul> </li> <li><h2>World Market Data</h2> <ul> [List Items removed for brevity] </ul> </li> <li><h2>Daily Market Data</h2> <ul> [List Items removed for brevity] </ul> </li> </ul> Option 2: Divs with h2 and lists <div id="mainpoints"> <div> <h2>Powerful Analysis</h2> <ul> <li>Charting and indicators</li> <li>Daily trading signals</li> <li>Company health checks</li> </ul> </div> <div> <h2>World Market Data</h2> <ul> [List Items removed for brevity] </ul> </div> <div> <h2>Daily Market Data</h2> <ul> [List Items removed for brevity] </ul> </div> </div> Option 3: Definition List <dl id="mainpoints"> <dt>Powerful Analysis</dt> <dd>- Charting and indicators</dd> <dd>- Daily trading signals</dd> <dd>- Company health checks</dd> <dt>World Market Data</dt> [List Items removed for brevity] <dt>Daily Market Data</dt> [List Items removed for brevity] </dl> My instincts tell me that semanticaly the pure list options (1 & 3) are the best and that h2 may be more SEO friendly (1 & 2) which would point to option 1 as being the best option. I do love the lean makeup of the definition list but will I take an SEO hit by losing the h2 tags? Before anyone asks, h2 is not valid markup in a dt tag. Are my instincts right with a nested list being the way to go?

    Read the article

  • kernel module compiling error

    - by wati
    sh@ubuntu:/home/ccpp/helloworld$ make gcc-4.6 -O2 -DMODULE -D_KERNEL_ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include -c -o hello-1.o hello-1.c hello-1.c:4:0: warning: "MODULE" redefined [enabled by default] <command-line>:0:0: note: this is the location of the previous definition hello-1.c:6:0: warning: "_KERNEL_" redefined [enabled by default] <command-line>:0:0: note: this is the location of the previous definition In file included from /lib/modules/3.2.0-25-generic/build/include/linux/list.h:4:0, from /lib/modules/3.2.0-25-generic/build/include/linux/module.h:9, from hello-1.c:7: /lib/modules/3.2.0-25-generic/build/include/linux/types.h:13:2: warning: #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders" [-Wcpp] In file included from /lib/modules/3.2.0-25-generic/build/include/linux/module.h:9:0, from hello-1.c:7: /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘INIT_LIST_HEAD’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:26:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:27:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘__list_add’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:41:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:42:5: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:43:5: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:44:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_add’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:62:28: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_add_tail’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:76:22: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘__list_del’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:88:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:89:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘__list_del_entry’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:101:18: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:101:31: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_del’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:106:18: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:106:31: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:107:7: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:108:7: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_replace’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:125:5: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:125:17: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:126:5: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:127:5: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:127:17: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:128:5: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_is_last’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:179:13: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_empty’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:188:13: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_empty_careful’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:206:31: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:207:40: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_rotate_left’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:219:15: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_is_singular’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:230:35: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:230:49: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘__list_cut_position’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:236:37: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:237:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:237:19: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:238:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:239:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:240:7: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:241:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:242:11: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_cut_position’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:265:8: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘__list_splice’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:277:32: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:278:31: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:280:7: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:281:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:283:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:284:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_splice’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:296:33: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_splice_tail’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:308:27: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_splice_init’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:322:33: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘list_splice_tail_init’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:339:27: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘INIT_HLIST_NODE’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:572:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:573:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘hlist_unhashed’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:578:11: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘hlist_empty’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:583:11: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘__hlist_del’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:588:29: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:589:31: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:592:7: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘hlist_del’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:598:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:599:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘hlist_add_head’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:612:30: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:613:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:615:8: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:615:20: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:616:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:617:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:617:15: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘hlist_add_before’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:624:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:624:17: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:625:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:626:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:626:18: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:627:5: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘hlist_add_after’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:633:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:633:16: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:634:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:635:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:635:18: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:637:9: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:638:7: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:638:29: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘hlist_add_fake’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:644:3: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:644:15: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h: In function ‘hlist_move_list’: /lib/modules/3.2.0-25-generic/build/include/linux/list.h:654:5: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:654:18: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:655:9: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:656:6: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:656:27: error: dereferencing pointer to incomplete type /lib/modules/3.2.0-25-generic/build/include/linux/list.h:657:5: error: dereferencing pointer to incomplete type In file included from /lib/modules/3.2.0-25-generic/build/include/linux/module.h:12:0, from hello-1.c:7: /lib/modules/3.2.0-25-generic/build/include/linux/cache.h: At top level: /lib/modules/3.2.0-25-generic/build/include/linux/cache.h:5:23: fatal error: asm/cache.h: No such file or directory compilation terminated. make: *** [hello-1.o] Error 1 i got this error after compiling an helloworld program my program is #define MODULE #define LINUX #define _KERNEL_ #include <linux/module.h> #include <linux/kernel.h> int init_module(void) { printk("<1>hello World 1.\n"); return 0; } void cleanup_module(void) { printk(KERN_ALERT "goodbye world 1.\n"); } MODULE_LICENSE("GPL"); my make file is: TARGET := hello-1 WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes INCLUDE := -isystem /lib/modules/`uname -r`/build/include CFLAGS := -O2 -DMODULE -D_KERNEL_ ${WARN} ${INCLUDE} CC := gcc-4.6 ${TARGET}.o: ${TARGET}.c .PHONY: clean clean: rm -rf ${TARGET}.o iam usin kernel 3.2.0.25 as novice i can't able to figure out where the problem is I SEARCHED EVERY THING I CAN TO KNOW ABOUT THIS ERROR BUT I CANT UNDERSTAND &I GET IRRELEVANT DOCS anybody help me please

    Read the article

  • Sorting a Linked List [closed]

    - by Mohit Sehgal
    I want to sort a linked list. Here Node is class representing a node in a Linked List I have written a code to bubble sort a linked list. Program does not finishes execution. Kindly point out the mistakes. class Node { public: int data; public: Node *next; Node() { data=0;next=0; } Node(int d) { data=d; } void setData(int d) { data=d; } void print() { cout<<data<<endl; } bool operator==(Node n) { return this->data==n.data; } bool operator >(Node d) { if((this->data) > (d.data)) return true; return false; } }; class LList { public: int noOfNodes; Node *start;/*Header Node*/ LList() { start=new Node; noOfNodes=0;start=0; } void addAtFront(Node* n) { n->next=(start); start=n; noOfNodes++; } void addAtLast(Node* n) { Node *cur=(start); n->next=NULL; if(start==NULL) { start=n; noOfNodes++; return; } while(cur->next!=NULL) { cur=cur->next; } cur->next=n; noOfNodes++; } void addAtPos(Node *n,int pos) { if(pos==1) { addAtFront(n);return; } Node *cur=(start); Node *prev=NULL; int curPos=0; n->next=NULL; while(cur!=NULL) { curPos++; if(pos==curPos+1) { prev=cur; } if(pos==curPos) { n->next=cur; prev->next=n; break; } cur=cur->next; } noOfNodes++; } void removeFirst() { Node *del=start; start=start->next; delete del; noOfNodes--; return; } void removeLast() { Node *cur=start,*prev=NULL; while(cur->next!=NULL) { prev=cur; cur=cur->next; } prev->next=NULL; Node *del=cur->next; delete del; noOfNodes--; return; } void removeNodeAt(int pos) { if(pos<1) return; if(pos==1) { removeFirst();return;} int curPos=1; Node* cur=start->next; Node* prev=start; Node* del=NULL; while(curPos<pos&&cur!=NULL) { curPos++; if(curPos==pos) { del=cur; prev->next=cur->next; cur->next=NULL; delete del; noOfNodes--; break; } prev=prev->next; cur=cur->next; } } void removeNode(Node *d) { Node *cur=start; if(*d==*cur) { removeFirst();return; } cur=start->next; Node *prev=start,*del=NULL; while(cur!=NULL) { if(*cur==*d) { del=cur; prev->next=cur->next; delete del; noOfNodes--; break; } prev=prev->next; cur=cur->next; } } int getPosition(Node data) { int pos=0; Node *cur=(start); while(cur!=NULL) { pos++; if(*cur==data) { return pos; } cur=cur->next; } return -1;//not found } Node getNode(int pos) { if(pos<1) return -1;// not a valid position else if(pos>noOfNodes) return -1; // not a valid position Node *cur=(start); int curPos=0; while(cur!=NULL) { if(++curPos==pos) return *cur; cur=cur->next; } } void reverseList()//reverse the list { Node* cur=start->next; Node* d=NULL; Node* prev=start; while(cur!=NULL) { d=cur->next; cur->next=start; start=cur; prev->next=d; cur=d; } } void sortBubble() { Node *i=start,*j=start,*prev=NULL,*temp=NULL,*after=NULL; int count=noOfNodes-1;int icount=0; while(i->next!=NULL) { j=start; after=j->next; icount=0; while(++icount!=count) { if((*j)>(*after)) { temp=after->next; after->next=j; prev->next=j->next; j->next=temp; prev=after; after=j->next; } else{ prev=j; j=after; after=after->next; } } i=i->next; count--; } } void traverse() { Node *cur=(start); int c=0; while(cur!=NULL) { // cout<<"start"<<start; c++; cur->print(); cur=cur->next; } noOfNodes=c; } ~LList() { delete start; } }; int main() { int n; cin>>n; int d; LList list; Node *node; Node *temp=new Node(2123); for(int i=0;i<n;i++) { cin>>d; node=new Node(d); list.addAtLast(node); } list.addAtPos(temp,1); cout<<"traverse\n"; list.traverse(); temp=new Node(12); list.removeNode(temp); cout<<"12 removed"; list.traverse(); list.reverseList(); cout<<"\nreversed\n"; list.traverse(); cout<<"bubble sort\n"; list.sortBubble(); list.traverse(); getch(); delete node; return 0; }

    Read the article

  • Invert linear linked list

    - by ArtWorkAD
    Hi, a linear linked list is a set of nodes. This is how a node is defined (to keep it easy we do not distinguish between node an list): class Node{ Object data; Node link; public Node(Object pData, Node pLink){ this.data = pData; this.link = pLink; } public String toString(){ if(this.link != null){ return this.data.toString() + this.link.toString(); }else{ return this.data.toString() ; } } public void inc(){ this.data = new Integer((Integer)this.data + 1); } public void lappend(Node list){ Node child = this.link; while(child != null){ child = child.link; } child.link = list; } public Node copy(){ if(this.link != null){ return new Node(new Integer((Integer)this.data), this.link.copy()); }else{ return new Node(new Integer((Integer)this.data), null); } } public Node invert(){ Node child = this.link; while(child != null){ child = child.link; } child.link = this;.... } } I am able to make a deep copy of the list. Now I want to invert the list so that the first node is the last and the last the first. The inverted list has to be a deep copy. I started developing the invert function but I am not sure. Any Ideas? Update: Maybe there is a recursive way since the linear linked list is a recursive data structure. I would take the first element, iterate through the list until I get to a node that has no child and append the first element, I would repeat this for the second, third....

    Read the article

  • C++ Bubble Sorting for Singly Linked List [closed]

    - by user1119900
    I have implemented a simple word frequency program in C++. Everything but the sorting is OK, but the sorting in the following script does not work. Any emergent help will be great.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <iostream> #include <fstream> #include <cstdio> using namespace std; #include "ProcessLines.h" struct WordCounter { char *word; int word_count; struct WordCounter *pNext; // pointer to the next word counter in the list }; /* pointer to first word counter in the list */ struct WordCounter *pStart = NULL; /* pointer to a word counter */ struct WordCounter *pCounter = NULL; /* Print statistics and words */ void PrintWords() { ... pCounter = pStart; bubbleSort(pCounter); ... } //end-PrintWords void bubbleSort(struct WordCounter *ptr) { WordCounter *temp = ptr; WordCounter *curr; for (bool didSwap = true; didSwap;) { didSwap = false; for (curr = ptr; curr->pNext != NULL; curr = curr->pNext) { if (curr->word > curr->pNext->word) { temp->word = curr->word; curr->word = curr->pNext->word; curr->pNext->word = temp->word; didSwap = true; } } } }

    Read the article

  • How to Name Linked Servers

    - by Bill Graziano
    I did another SQL Server migration over the weekend that dealt with linked servers.  I’ve seen all kinds of odd naming schemes and there are a few I like and a few I suggest you avoid. Don’t name your linked server for its IP address.  At some point whatever is on the other end of that IP address will move.  You’ll probably need to point your linked server to a new IP address but not change the name of the linked server.  And then you’ve completely lost any context around this.  Bonus points if a new SQL Server eventually ends up at the old IP address further adding confusion when you’re trying to troubleshoot. Don’t name your linked server based on its instance name.  This one is less obvious.  It sounds nice to have a linked server named [VSRV1\SQLTRAN01].  You know what it is and it’s easy to use.  It’s less nice when you’ve got 200 stored procedures that all reference this linked server but the database they reference has moved to a new instance.  Now when you query this you’re actually querying a different instance. (Please note: I’m not saying it’s a good idea to have 200 stored procedures that all reference a linked server.  I’m just saying it’s not all that uncommon.) Consider naming your linked server something that you can easily search on.  See my note above.  You can also get around this by always enclosing the name in brackets.  That is harder to enforce unless you use some odd characters in it. Consider naming your linked server based on the function.  For example, I’ve had some luck having a linked server named [DW] that points to our data warehouse server.  That server can change names or physically move and all I need to do is update the linked server to point to the new destination.  The descriptive name of the linked server is still accurate.  No code needs to change and people still know what it is just by looking at it. Consider naming your linked server for the database.  I’m still thinking through this one.  It may mean you have multiple linked servers that point to the same instance.  I’ve found that database names rarely change.  It also makes it easier to move individual databases to new servers. Consider pointing your linked servers to DNS entries and not IP addresses.  I’ve done this for reporting databases and had some success.  Especially for read-only snapshots that can get created on the main database or on the mirror.  What issues have you had with linked server names?  What has worked for you?  Where are the holes in my approach?

    Read the article

  • Doubly Linked Lists Implementation

    - by user552127
    Hi All, I have looked at most threads here about Doubly linked lists but still unclear about the following. I am practicing the Goodrich and Tamassia book in Java. About doubly linked lists, please correct me if I am wrong, it is different from a singly linked list in that a node could be inserted anywhere, not just after the head or after the tail using both the next and prev nodes available, while in singly linked lists, this insertion anywhere in the list is not possible ? If one wants to insert a node in a doubly linked list, then the default argument should be either the node after the to-be inserted node or node before the to-be inserted node ? But if this is so, then I don't understand how to pass the node before or after. Should we be displaying all nodes that were inserted till now and ask the user to select the node before or after which some new node is to be inserted ? My doubt is how to pass this default node. Because I assume that will require the next and prev nodes of these nodes as well. For e.g, Head<-A<-B<-C<-D<-E<-tail If Z is the new node to be inserted after say D, then how should node D be passed ? I am confused with this though it seems pretty simple to most. But pl do explain. Thanks, Sanjay

    Read the article

  • Can we have Linked Servers when using NTLM?

    - by BlueRaja
    I don't have access to the Active Directory settings, nor do I have access to change anything on the linked server. From everything I've read, it seems like this means I cannot use Kerberos - which is a big problem, because I don't know how to use a linked server without it. Is there any way to connect to a linked server without Kerberos? Exact problem description When I connect to the linked server while sitting in front of my server, it works fine; but when I try to connect to the linked server from any other computer (delegating through my server), it gives the error: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. (Microsoft SQL Server, Error: 18456) It seems that this is the "double-hop problem," and the usual solution is to enable Kerberos, which requires access to AD and the linked server. I get the same error when I set security to "Be made using the login's current security context," and I can't use "Be made using this security context" because that appears to use SQL-authentication (which is not enabled on the linked server) instead of NTLM

    Read the article

  • Test if single linked list is circular by traversing it only once

    - by user1589754
    I am a fresher and I was asked this question in a recent interview I gave. The question was --- By traversing each element of linked list just once find if the single linked list is circular at any point. To this I answered that we will store reference of each node while traversing the list in another linked list and for every node in the list being tested we will find if the reference exists in the list I am storing the references. The interviewer said that he needs a more optimized way to solve this problem. Can anyone please tell me what would be a more optimized method to solve this problem.

    Read the article

  • linked list elements gone?

    - by Hristo
    I create a linked list dynamically and initialize the first node in main(), and I add to the list every time I spawn a worker process. Before the worker process exits, I print the list. Also, I print the list inside my sigchld signal handler. in main(): head = NULL; tail = NULL; // linked list to keep track of worker process dll_node_t *node; node = (dll_node_t *) malloc(sizeof(dll_node_t)); // initialize list, allocate memory append_node(node); node->pid = mainPID; // the first node is the MAIN process node->type = MAIN; in a fork()'d process: // add to list dll_node_t *node; node = (dll_node_t *) malloc(sizeof(dll_node_t)); append_node(node); node->pid = mmapFileWorkerStats->childPID; node->workerFileName = mmapFileWorkerStats->workerFileName; node->type = WORK; functions: void append_node(dll_node_t *nodeToAppend) { /* * append param node to end of list */ // if the list is empty if (head == NULL) { // create the first/head node head = nodeToAppend; nodeToAppend->prev = NULL; } else { tail->next = nodeToAppend; nodeToAppend->prev = tail; } // fix the tail to point to the new node tail = nodeToAppend; nodeToAppend->next = NULL; } finally... the signal handler: void chld_signalHandler() { dll_node_t *temp1 = head; while (temp1 != NULL) { printf("2. node's pid: %d\n", temp1->pid); temp1 = temp1->next; } int termChildPID = waitpid(-1, NULL, WNOHANG); dll_node_t *temp = head; while (temp != NULL) { if (temp->pid == termChildPID) { printf("found process: %d\n", temp->pid); } temp = temp->next; } return; } Is it true that upon the worker process exiting, the SIGCHLD signal handler is triggered? If so, that would mean that after I print the tree before exiting, the next thing I do is in the signal handler which is print the tree... which would mean i would print the tree twice? But the tree isn't the same. The node I add in the worker process doesn't exist when I print in the signal handler or at the very end of main(). Any idea why? Thanks, Hristo

    Read the article

  • Singly-Linked Lists insert_back and isIncreasing

    - by rezivor
    I just finished writing a program that I can add, remove or print objects to a list, but I am having difficulty implementing two more functions that is insert_back, which inserts a value to the end of a list. Also,I have to modify the representation of a List and alter whatever methods are necessary to make insert_back run in constant time: O(1). This new operation should have the signature: void List::insert_back( const Object& data ); Also, isIncreasing, For example, for a list containing head-() (11) (8) (15) (3), isIncreasing() should return false. However, it would return true when working on a list containing head- () (7) (9) (15). This new operation should have the signature: bool List::isIncreasing() const; Thank you

    Read the article

  • Doubly linked lists

    - by user1642677
    I have an assignment that I am terribly lost on involving doubly linked lists (note, we are supposed to create it from scratch, not using built-in API's). The program is supposed to keep track of credit cards basically. My professor wants us to use doubly-linked lists to accomplish this. The problem is, the book does not go into detail on the subject (doesn't even show pseudo code involving doubly linked lists), it merely describes what a doubly linked list is and then talks with pictures and no code in a small paragraph. But anyway, I'm done complaining. I understand perfectly well how to create a node class and how it works. The problem is how do I use the nodes to create the list? Here is what I have so far. public class CardInfo { private String name; private String cardVendor; private String dateOpened; private double lastBalance; private int accountStatus; private final int MAX_NAME_LENGTH = 25; private final int MAX_VENDOR_LENGTH = 15; CardInfo() { } CardInfo(String n, String v, String d, double b, int s) { setName(n); setCardVendor(v); setDateOpened(d); setLastBalance(b); setAccountStatus(s); } public String getName() { return name; } public String getCardVendor() { return cardVendor; } public String getDateOpened() { return dateOpened; } public double getLastBalance() { return lastBalance; } public int getAccountStatus() { return accountStatus; } public void setName(String n) { if (n.length() > MAX_NAME_LENGTH) throw new IllegalArgumentException("Too Many Characters"); else name = n; } public void setCardVendor(String v) { if (v.length() > MAX_VENDOR_LENGTH) throw new IllegalArgumentException("Too Many Characters"); else cardVendor = v; } public void setDateOpened(String d) { dateOpened = d; } public void setLastBalance(double b) { lastBalance = b; } public void setAccountStatus(int s) { accountStatus = s; } public String toString() { return String.format("%-25s %-15s $%-s %-s %-s", name, cardVendor, lastBalance, dateOpened, accountStatus); } } public class CardInfoNode { CardInfo thisCard; CardInfoNode next; CardInfoNode prev; CardInfoNode() { } public void setCardInfo(CardInfo info) { thisCard.setName(info.getName()); thisCard.setCardVendor(info.getCardVendor()); thisCard.setLastBalance(info.getLastBalance()); thisCard.setDateOpened(info.getDateOpened()); thisCard.setAccountStatus(info.getAccountStatus()); } public CardInfo getInfo() { return thisCard; } public void setNext(CardInfoNode node) { next = node; } public void setPrev(CardInfoNode node) { prev = node; } public CardInfoNode getNext() { return next; } public CardInfoNode getPrev() { return prev; } } public class CardList { CardInfoNode head; CardInfoNode current; CardInfoNode tail; CardList() { head = current = tail = null; } public void insertCardInfo(CardInfo info) { if(head == null) { head = new CardInfoNode(); head.setCardInfo(info); head.setNext(tail); tail.setPrev(node) // here lies the problem. tail must be set to something // to make it doubly-linked. but tail is null since it's // and end point of the list. } } } Here is the assignment itself if it helps to clarify what is required and more importantly, the parts I'm not understanding. Thanks https://docs.google.com/open?id=0B3vVwsO0eQRaQlRSZG95eXlPcVE

    Read the article

  • Testing if a list contains another list with Python

    - by None
    How can I test if a list contains another list. Say there was a function called contains: contains([1,2], [-1, 0, 1, 2]) # Returns [2, 3] (contains returns [start, end]) contains([1,3], [-1, 0, 1, 2]) # Returns False contains([1, 2], [[1, 2], 3) # Returns False contains([[1, 2]], [[1, 2], 3]) # Returns [0, 0] Edit: contains([2, 1], [-1, 0, 1, 2]) # Returns False contains([-1, 1, 2], [-1, 0, 1, 2]) # Returns False contains([0, 1, 2], [-1, 0, 1, 2]) # Returns [1, 3]

    Read the article

  • Deleting a node from linked list in C

    - by LuckySlevin
    My problem is deleting a node from linked list. I have two structs : typedef struct inner_list { int count; char word[100]; inner_list*next; } inner_list; typedef struct outer_list { char word [100]; inner_list * head; int count; outer_list * next; } outer_list; My problem is in deleting a node from outer_list linked list. For example when user entered aaa to delete, delete function should find the node with outer_list->word = aaa and delete this node and reconnect the list again. I tried the below code to do this. but After finding and deleting I'm losing the list. I don't know what's wrong. Please notice that outer_list have also a linked list of inner_list inside. void delnode(outer_list *head,char num[100]) { outer_list *temp, *m; temp=head; while(temp!=NULL) { if(strcmp(temp->word==num)==0) { if(temp==head) { head=temp->next; free(temp); return; } else { m->next=temp->next; free(temp); return; } }else { m=temp; temp= temp->next; } } printf(" ELEMENT %s NOT FOUND ", num); } What are your ideas about this?

    Read the article

  • Multithreaded linked list traversal

    - by Rob Bryce
    Given a (doubly) linked list of objects (C++), I have an operation that I would like multithread, to perform on each object. The cost of the operation is not uniform for each object. The linked list is the preferred storage for this set of objects for a variety of reasons. The 1st element in each object is the pointer to the next object; the 2nd element is the previous object in the list. I have solved the problem by building an array of nodes, and applying OpenMP. This gave decent performance. I then switched to my own threading routines (based off Windows primitives) and by using InterlockedIncrement() (acting on the index into the array), I can achieve higher overall CPU utilization and faster through-put. Essentially, the threads work by "leap-frog'ing" along the elements. My next approach to optimization is to try to eliminate creating/reusing the array of elements in my linked list. However, I'd like to continue with this "leap-frog" approach and somehow use some nonexistent routine that could be called "InterlockedCompareDereference" - to atomically compare against NULL (end of list) and conditionally dereference & store, returning the dereferenced value. I don't think InterlockedCompareExchangePointer() will work since I cannot atomically dereference the pointer and call this Interlocked() method. I've done some reading and others are suggesting critical sections or spin-locks. Critical sections seem heavy-weight here. I'm tempted to try spin-locks but I thought I'd first pose the question here and ask what other people are doing. I'm not convinced that the InterlockedCompareExchangePointer() method itself could be used like a spin-lock. Then one also has to consider acquire/release/fence semantics... Ideas? Thanks!

    Read the article

  • Hover effect for parent unordered list inherited by child list

    - by elvista
    I have a simple menu <ul id="menu"> <li class="leaf"><a href="#">Menu Item 1</a></li> <li class="leaf"><a href="#">Menu Item 2</a></li> <li class="expanded"><a href="#">Menu Item 3</a> <ul> <li class="leaf"><a href="#">Menu Item a</a></li> <li class="leaf"><a href="#">Menu Item b</a></li> <li class="leaf"><a href="#">Menu Item c</a></li> </ul> </li> <li class="leaf"><a href="#">Menu Item 4</a></li> </ul> and ul#menu li a:hover {font-weight:bold;} The problem I am facing is when I hover above a ul li li, the parent as well as all its siblings gets the hover effect. I only want the list item I hovered above to get the effect. I tried ul#menu li.leaf a: hover {..}, ul#menu li.expanded a: hover {..} , but even in that case, when I hover above li.expanded, it's child inherits the style. How do I fix this?

    Read the article

  • C++ classes & linked list: adding & counting items

    - by user342289
    I need to make a linked list with classes. Each list will store two values: a URI and IP. After doing all the adding, I need to be able count the total number of items in the linked list. I have tried the following code but it doesn't compile. Any suggestions please? #include <iostream> #include <cstdlib> #include <string> using namespace std; class ip_uri_store { protected: string ip; string uri; ip_uri_store *next; public: ip_uri_store(string huri, string hip); void additem(string auri, string aip); void deleteitem(string duri); void findbyuri(string furi); void findbyip(string fip); int totalitems(); }; ip_uri_store *head = NULL; ip_uri_store *curr = NULL; void ip_uri_store::additem(string auri, string aip) { curr = head; while (curr->next != NULL) { curr = curr->next; } curr->uri = auri; curr->next = new ip_uri_store; curr->ip = aip; curr->next = new ip_uri_store; curr = curr->next; curr = head; } int ip_uri_store::totalitems() { int i = 0; curr = head; while (curr->next != NULL) { i += 1; curr = curr->next; } return i; } int main(int argc, char *argv[]) { if (argc == 1) { cout << "123456, [email protected], Gordon Brown" << endl; return (0); } head = new ip_uri_store; curr = head; int i; for (i = 1; i < argc; i++) { if (argv[i][0] == 'A') //add item { ip_uri_store.additem(argv[i + 1], argv[i + 2]); i += 2; } else if (argv[i][0] == 'N') //print total tiems { cout << ip_uri_store.totalitems() << endl; } else { cout << "command error\n"; return 0; } } return (0); }

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >