answersLogoWhite

0


Best Answer

Write a program that inputs a series of integers and passes them one at a time to a function even which uses the remainder operator to determine if an integer is even. The function should take an integer argument and return 1 if the integer is even and 0 otherwise.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

to create a linked list at first we need to design the structure of node i.e. what kind of data it is having. after creating node we will make a start node.

e.g.

struct node

{

int info;

struct node * next;

}

node *start,*y,*z;

void main()

{

x=malloc(sizeof(struct node));

printf("enter the data");

scanf("%d",&x->info);

start=y=x;

while(x->info!=0) // termination condition

{

x=malloc(sizeof(struct node));

printf("enter the data");

scanf("%d",&x->info);

y->next=x;

y=x;

}

x->next=NULL; // end node

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

First, you need to decide whether you want a singly-linked list or a doubly-linked list.

The advantage of a doubly-linked list is that you can traverse it forwards or backwards, and it's easier to remove the tail element.

Then, you need to define a structure for the nodes:

Singly-linked version:

struct node {

struct node *next;

void *data;

};

typedef struct node node;

Doubly linked version:

struct node {

struct node *next;

struct node *previous;

void *data;

};

typedef struct node node;

You need to dynamically allocate nodes using malloc, because you don't know how many there are going to be.

You need to write a function that has a declaration something like this:

node *node_create(void *data);

You need to keep track of one node in the list, which is the head (and tail), so for this and other reasons it's a good idea to make the list itself a structure:

typedef struct {

node *head;

} circularlist;

And you'll need functions to create the list using malloc and delete it using free:

circularlist *circularlist_create(void);

void circularlist_delete(circularlist *list);

Once you've done that, you need to write the functions to add data.

Which functions you want is up to you, but these are some possibilities:

void circularlist_add_head(circularlist *list, void *data);

void circularlist_add_tail(circularlist *list, void *data);

void circularlist_add(circularlist *list, void *data, node *predecessor);

The fun part is implementing these functions to create nodes and link them together.

When you want to iterate over the list, you need to do something like this:

node = list->head;

do {

printf("%s\n", (const char*)node->data);

node = node->next;

} while (node != list->head);

Make sure you delete all of the nodes when you delete the list.

Be aware that when you have deleted a node, its next pointer is no longer valid, so you may need to use a temporary variable.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

A linked list is a list of data that is in an unordered sequence. Each piece of data contains the location of the next piece of data in an ordered (sorted) sequence.

The last piece of data in the ordered (sorted) sequence has the location of the next piece of data set to the very first piece of data (in the ordered (sorted) sequence). This makes the list circular because the is no physical end just a logical end.

A circular linked list is searched by first picking on any particular data set and inspecting it for desired match. If the match is not found then the data set is read using the location of the current data set. If the desired match is not found, eventually the location of the next data set will be the very first data set that was inspected indicating that the search has performed a full circle and the desired match does not exist.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

To create a linked list you need to create a class/structure and assign it a pointer to another instance of same class/structure.

For example:

typedef struct list

{

struct list *next;

int a;

} list;

Here the next pointer in the structure will refer to the next element in the list.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Yes, if there is no first and last element, but the elements for a (bi-directional) cícle.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you use doubly linked list as a circular linked?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is difference between linked list and singly linked list?

Answersingly linked list has the node inserted only at one end. and the pointer corresponds to the next pointer.but in a doubly linked list, the node pointer points to the both previous and the next node.singly linked list has two nodesdoubly linked list has three nodesA doubly linked list makes sense when you need to traverse the list in both directions. You aren't able to do that with a singly linked list.


How do you write a Java program to implement weighted queue using circular doubly linked list?

Add weights to the elements of the queue and use an algorithm to sort the queue every time an element is added.


Why you use doubly link list?

In a doubly linked list, you can iterate backwards as easily as forwards, as each element contains links to both the prior and the following element. You can also insert or delete an element without needing to iterate and remember the prior element's link. This comes at a cost. You are adding storage to each element for the second link, and you are adding processing overhead to the insert and delete operation. You have to determine the tradeoff.


Disadvantages of circular link list as compared to singly link list?

As compared with doubly-linked lists, one disadvantage is that singly-linked lists can only be efficiently traversed in one direction. Finding the (n - 1)th element, given only a pointer to the nth, requires scanning the list from the first element up to the (n - 1)th. Thus (if memory is too limited to permit tricks such as creating a reversed list) to iterate over the entire list in reverse order would require n + (n - 1) + ... + 1 = n(n + 1)/2 link traversals, which grows quadratically with n. Obviously for a doubly-linked list the time merely grows linearly with n.A down-side of all linked lists versus arrays is that random access can be inefficient; the time taken to find an element with a randomly chosen index grows in direct proportion to the list's length (since we must scan from one of the ends). In contrast, an array allows us to index directly to the elements with simple pointer arithmetic, in a time independent of the array's size - at least in an idealised environment.


What are circular doubly linked lists?

circular linked list is type of linked list used in data structure where address of 1st node is stored in the link part of last node data1link1 ................... datanlinkn address1 here linkn=adress1 (node1) (noden) pratima patwa

Related questions

C program to implement deque using circular linked list?

You'll need to use a doubly-linked circular list, since otherwise when you pop off the tail element you'll need to whizz all the way round the list to find its predecessor. See the links section for an implementation of a doubly-linked circular list.


Can we use doubly linked list as a circular linked list?

Yes. The tail node's next node is the head node, while the head node's previous node is the tail node.


What is difference between linked list and singly linked list?

Answersingly linked list has the node inserted only at one end. and the pointer corresponds to the next pointer.but in a doubly linked list, the node pointer points to the both previous and the next node.singly linked list has two nodesdoubly linked list has three nodesA doubly linked list makes sense when you need to traverse the list in both directions. You aren't able to do that with a singly linked list.


How do you write a Java program to implement weighted queue using circular doubly linked list?

Add weights to the elements of the queue and use an algorithm to sort the queue every time an element is added.


What are the differences between singly-linked doubly-linked and circularly-linked lists?

The difference is how many pointers each node has, and what they are pointing to. A linked list is comprised of "Nodes" each node contains data as well as 1 or more pointers. A singly linked list has one pointer per node, and a doubly linked list has 2 pointers per node. Some programs use several pointers per node. The purpose of these pointers is to hold the list together. In a singly linked list, you can view a node and can then move on to the next node that it is pointing to until you've passed through them all. A doubly-linked list would have a pointer to the next node as well as to the previous node. Thus you can move forward and backward through the list. A circularly-linked list doesn't necessarily have a set number of pointers because it simply means that the last node points to the first node creating a big circle. A non-circularly-linked list would not contain this last to first pointer and thus you would eventually reach the end of the list and stop.


Why you use doubly link list?

In a doubly linked list, you can iterate backwards as easily as forwards, as each element contains links to both the prior and the following element. You can also insert or delete an element without needing to iterate and remember the prior element's link. This comes at a cost. You are adding storage to each element for the second link, and you are adding processing overhead to the insert and delete operation. You have to determine the tradeoff.


Disadvantages of circular link list as compared to singly link list?

As compared with doubly-linked lists, one disadvantage is that singly-linked lists can only be efficiently traversed in one direction. Finding the (n - 1)th element, given only a pointer to the nth, requires scanning the list from the first element up to the (n - 1)th. Thus (if memory is too limited to permit tricks such as creating a reversed list) to iterate over the entire list in reverse order would require n + (n - 1) + ... + 1 = n(n + 1)/2 link traversals, which grows quadratically with n. Obviously for a doubly-linked list the time merely grows linearly with n.A down-side of all linked lists versus arrays is that random access can be inefficient; the time taken to find an element with a randomly chosen index grows in direct proportion to the list's length (since we must scan from one of the ends). In contrast, an array allows us to index directly to the elements with simple pointer arithmetic, in a time independent of the array's size - at least in an idealised environment.


What is the difference between queues and circular queues?

A queue can use a dynamic array, or a linked list, but if using static memory, the queue becomes a circular queue because the underlaying data structure is a static circular array. This means the ends of the array are attached.


Is Far pointer necessary to create a circular linked list?

It has to be a pointer all right.Regarding 'far' and 'near': forget it, simply use 'Large' data modell (or 'Huge').


What are circular doubly linked lists?

circular linked list is type of linked list used in data structure where address of 1st node is stored in the link part of last node data1link1 ................... datanlinkn address1 here linkn=adress1 (node1) (noden) pratima patwa


Where linked list using?

linked list are used for creation of stack,queues to use memory in optimum manner linked list are used as they are dynamic in nature


What are the Circular singly linked list applications in real life?

best example is trains...where each coach is connected to next coach except the engine and the last coach..when we need to add a coach we need to move to the right position and adjust the connecting point suitably!!