Hi guys or gals ,
i'm in trouble with my class teacher, with in two days i have to finish my lab work .... i'm in need of c program using linked list
my concept is
1. creating a linked list
2.Inserting a number in front of it
3.Insert a nubmber last of it.
4.Searching a number in the created list
5.Deleting a number from the list
6.Deleting the first number
7.Deleting Last Number

I tried little bit
please help me with the same datamembers ..

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct list
{
 int data;
struct list *next;
}*head,*temp,*node;
typedef struct list sl;
void main()
{
 node=(sl*)malloc(sizeof(sl));
printf("Enter the numbers");
scanf("%d",&node->data);
if(head==Null)
{
 head=node;

below that i dont know how to do please help me

And how long did you spend on this?

Draw it on paper! Use multiple colors to work out insertions and removals.

Your amount of code is inadequate. Maybe spend more time listening in the classroom and taking notes? Work on a team with fellow classmates?

What I'm providing here is really TOO much information for the microscopic amount of work you did!

Unswizzle your structure, especially since you are typedefingi it

typedef struct list
{
    int data;
    list *next;
} list;

list *head,*temp,*node;


Pre-initialize!
Head = NULL;


If insertion of a node at front of list
Allocate the node
if Node != NULL then allocation successful!

Node->next = Head <-- What was head pointing at?
Head = Node <-- Head now points to new node

Repeat for each prepended node!

If all new nodes are to be appeneded

Node *pPre;
if (NULL == Head)      // First in list
       do it like above
else
       pTmp = Head
      while ( NULL !=pTmp->next)         Loop until there is no next 
           pTmp = pTmp->next

      pTmp is NOW last node
      pNode->next = NULL
      pTmp->next = pNode

For node removal, since you are using a single-linked list you need to have your node to be removed to be the one after the node you're referencing.

if node First in list
  head = head->next->next;         
else                     <-- ptmp is before the node to remove
   pTmp->next  = pTmp->next->next;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.