Programme in c to create a single linked list, Data Structure & Algorithms

Q. Write  down a   programme  in  C  to  create  a  single  linked  list also  write the functions to do the following operations

(i)  To insert a new node at the end

(ii) To delete the first node                                                                                                                                     

Ans:

//Create a single list

struct node

{

int data;

struct node *link

}

struct node *p,*q;

//Inserting a node at the end(append)

append(struct node **q,int num)

{

struct node *temp; temp=*q; if(*q==NULL)

{

*q=malloc(sizeof(struct node *));

temp=*q;

}

else

{

while(temp        link!=NULL)

temp=temp   link;

temp   link = malloc(sizeof(struct node *));

temp=temp   link;

}

Temp   data=num;

temp     link=NULL;

}

//Delete the first node delete(struct node *q,int num)

{

struct node *temp;

temp=*q;

*q=temp   link;

free(temp);

}

Posted Date: 7/10/2012 7:08:48 AM | Location : United States







Related Discussions:- Programme in c to create a single linked list, Assignment Help, Ask Question on Programme in c to create a single linked list, Get Answer, Expert's Help, Programme in c to create a single linked list Discussions

Write discussion on Programme in c to create a single linked list
Your posts are moderated
Related Questions

Suppose we have a set of N agents and a set of N tasks.Each agent can only perform exactly one task and there is a cost associated with each assignment. We would like to find out a

The following are several operations on a AA-tree: 1. Searching: Searching is done using an algorithm which is similar to the search algorithm of a binary search tree. 2. Ins

Program: Creation of Doubly Linked List OUTPUT Input the values of the element -1111 to come out : 1 Input the values of the element -1111 to come out : 2 Inpu

How can the third dimension be displayed on the screen The main problem in visualization is the display of three-dimensional objects and scenes on two-dimensional screens. How

#question.explain different types of errors in data transmission.

how to implement prims algorithm dynamically

Z-Buffer Algorithm Also known as the Depth-Buffer algorithm, this image-space method simply selects for  display the polygon or portion of a polygon that is nearest to the view

Q.  In the given figure find the shortest path from A to Z using Dijkstra's Algorithm.    Ans: 1.  P=φ;  T={A,B,C,D,E,F,G,H,I,J,K,L,M,Z} Let L(A)

PART- Pest Control Program Prepare a Pest Control Program for the facility that will address the management of Rodents, Insects and Birds. Your Pest Control Program should