answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

#include<alloc.h>

#define NULL 0

int item,ch;

struct slink

{

int data;

struct slink *next;

}

*start,*new,*l;

main()

{

clrscr();

start=NULL;

printf("\n**MENU**");

printf("\n1.CREATE \n2.PRINT \n3.EXIT ");

while(1)

{

printf("\nENTER YOUR CHOICE: ");

scanf("%d",&ch);

switch(ch)

{

case 1: create();

break;

case 2: print();

break;

default: exit();

break;

}

}

getch();

}

create()

{

start=NULL;

l=start;

printf("\nENTER THE DATA: \n");

scanf("%d",&item);

while(item!=0)

{

new=malloc(sizeof(struct slink));

new->data=item;

new->next=NULL;

if(start==NULL)

{

start=new;

l=new;

}

else

{

l->next=new;

l=l->next;

}

printf("\nENTER 0 TO TERMINATE: \n");

scanf("%d",&item);

}

}

print()

{

l=start;

while(l!=NULL)

{

printf("%d--> ",l->data);

l=l->next;

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you print the elements of singly linked list-program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When is a doubly linked list appropriate?

Whenever you need constant time access to both the head and tail of the list and require bi-directional traversal of the list from any given node (not necessarily the head or tail).With a singly linked list, the only way to perform a reverse traversal is through a recursive call. For instance, the following C function will print singly linked nodes in reverse order (the caller simply passes the head node to the function):void print_reverse(node* current){if( current ){print_reverse( current->next);current->print(); }}While this works, for long lists there's a risk you might run out of stack space. This is because the head node (in the initial call) cannot print itself until the recursive call to the next node has returned, which it can't do until its recursive call returns, and so on until the recursion reaches the tail node. Only then will the recursions begin to unwind and the nodes can actually print themselves. Even if stack space isn't an issue, it's inefficient because you are effectively traversing the list twice; forwards to get to the tail and then backwards to do the actual printing.With a doubly-linked list you simply traverse the list from the tail node to the head node in order to print them in reverse order:void print_reverse(list& List){node* current = List.tail;while( 0 != current ){current->print();current = current->prev; }}While not quite as concise as a recursive call, it is a good deal more efficient.The other advantage is that should you have a reference to any node (whether the head, the tail or anything in between), you have the option to traverse forwards or backwards as you see fit. With a singly linked list you can only go forwards from a given node unless you used recursion to get to that node in the first place.


How do you Print data of all nodes of linked list?

Traverse the list from the head to the tail. Upon visiting each node, print the data it stores or refers to.


Write a unix program to print print a pattern?

echo 'print a pattern'


What is the difference between print preview and print command?

the print command gives an order to the computer to print a page but the print preview gives us a preview of the way in which it has to be printed


To print hello?

Print 'Hello';

Related questions

When is a doubly linked list appropriate?

Whenever you need constant time access to both the head and tail of the list and require bi-directional traversal of the list from any given node (not necessarily the head or tail).With a singly linked list, the only way to perform a reverse traversal is through a recursive call. For instance, the following C function will print singly linked nodes in reverse order (the caller simply passes the head node to the function):void print_reverse(node* current){if( current ){print_reverse( current->next);current->print(); }}While this works, for long lists there's a risk you might run out of stack space. This is because the head node (in the initial call) cannot print itself until the recursive call to the next node has returned, which it can't do until its recursive call returns, and so on until the recursion reaches the tail node. Only then will the recursions begin to unwind and the nodes can actually print themselves. Even if stack space isn't an issue, it's inefficient because you are effectively traversing the list twice; forwards to get to the tail and then backwards to do the actual printing.With a doubly-linked list you simply traverse the list from the tail node to the head node in order to print them in reverse order:void print_reverse(list& List){node* current = List.tail;while( 0 != current ){current->print();current = current->prev; }}While not quite as concise as a recursive call, it is a good deal more efficient.The other advantage is that should you have a reference to any node (whether the head, the tail or anything in between), you have the option to traverse forwards or backwards as you see fit. With a singly linked list you can only go forwards from a given node unless you used recursion to get to that node in the first place.


How do you Print data of all nodes of linked list?

Traverse the list from the head to the tail. Upon visiting each node, print the data it stores or refers to.


What are all the components of a print ad?

Text, image and organization of elements.


What if the signature on the poster was written in paint?

My poster/print has textual and graphic elements including a written signature in paint. Is this a poster or print?


What is print layout view?

It is the view that shows you how the document will look if you print it.


What kind of frame should you use for a print?

There are different approaches that can be taken to framing a print. But whatever the approach used, the colors and style of both the frame and the matting will substantially affect how the print is perceived. We feel that the artwork should be framed for the enhancement of the art itself. To accomplish this in framing a print, select mat colors from the colors in the print itself. This tends to bring out the colors in the print and lead attention into the print, rather than distract from it. The same with the frame: Try to pick framing materials that repeat textures, patterns and other elements in the print itself. Framing elements that are totally different in appearance from the elements in the print tend to pull attention to the frame and off the art work; this you want to avoid. The end result should be pleasing to the eye, and contribute to&mdash;not distract from&mdash;the perception of the print itself. What about the environment? If the artwork itself is suitable to the environment, a frame designed as abo


What kind of writing is the combination of cursive and print?

The combination of cursive and print is often referred to as &quot;cursive print&quot; or &quot;hybrid writing.&quot; This hybrid style incorporates elements of both cursive and print handwriting, resulting in a unique and personalized way of writing.


How to Print data of all nodes of linked list?

for (node=head; node!=null; node=node-&gt;next) printnode(node);


What are the four elements of a print ad?

Headline, graphics, copy, and signature.


What elements is part of the Microsoft netware environment for windows xp professional?

NWLink and NetWare File and Print Services


When you print a web page all elements must be printed including the pictures and text true or false?

No its false.


Print fonts and sizes are media elements that are commonly used by?

Print fonts and sizes are media elements that are commonly used by graphic designers, advertisers, and publishers to convey information effectively and enhance visual appeal in print materials such as magazines, brochures, and advertisements. They play a key role in defining the overall look and feel of a design and can impact readability and viewer engagement.