| | |
Need of linked list program
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 2
Reputation:
Solved Threads: 0
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 ..
below that i dont know how to do please help me
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 ..
c Syntax (Toggle Plain Text)
#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
Last edited by John A; Jul 30th, 2009 at 2:31 am. Reason: added code tags
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
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
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.
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
C Syntax (Toggle Plain Text)
typedef struct list { int data; list *next; } list;
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
C Syntax (Toggle Plain Text)
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.
C Syntax (Toggle Plain Text)
if node First in list head = head->next->next; else <-- ptmp is before the node to remove pTmp->next = pTmp->next->next;
Last edited by wildgoose; Jul 29th, 2009 at 2:46 pm.
![]() |
Similar Threads
- Major Problem with Doubly linked list program (C++)
- Linked List program HELP (C++)
- help with Sorting a Linked list is needed! (C++)
- trouble with double linked list (C++)
- Doubly Linked List Problem (C++)
- Adding to linked list from external file (C)
- I need help with a linked list program (C++)
- printing a linked list (C++)
Other Threads in the C Forum
- Previous Thread: Beginner C Question
- Next Thread: Simple Question regarding char Ptrs
| Thread Tools | Search this Thread |
Tag cloud for C
* adobe api append array arrays bash binarysearch centimeter char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax directory drawing dynamic executable execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux highest homework i/o ide infiniteloop initialization interest intmain() keyboard kilometer lazy license linked linkedlist linux linuxsegmentationfault list match matrix meter microsoft mqqueue multi mysql oddnumber odf open openwebfoundation pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scheduling segmentationfault send shape single socketprogramming spoonfeeding stack standard strchr string strings student suggestions system test testautomation unix urboc user whythiscodecausesegmentationfault win32api windows.h





