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 ..

struct list
 int data;
struct list *next;
typedef struct list sl;
void main()
printf("Enter the numbers");

below that i dont know how to do please help me

7 Years
Discussion Span
Last Post by wildgoose

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;

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
       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;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.