can you please spend a little time evaluating this code.
I can not run it successfully thanks :) - #include<stdio.h>
-
#include<conio.h>
-
#include<stdlib.h>
-
#define SIZE 10
-
-
typedef struct dlist
-
{
-
int val;
-
struct dlist *next,*prev;
-
}*dll;
-
//---------------- FUNCTION SEARCH_VAL --------------------------------------
-
dll search_val(dll head,int data)
-
{
-
dll temp;
-
temp=head;
-
while(temp)
-
{
-
if(temp->val==data)
-
return(1);
-
else
-
temp=temp->next;
-
}
-
return(0);
-
}
-
//---------------- FUNCTION ADD_BEG -----------------------------------------
-
void add_beg(dll head,dll n_new)
-
{
-
dll temp;
-
temp=head;
-
while(temp->prev!=NULL)
-
temp=temp->prev;
-
-
n_new->next=temp->next;
-
temp->next->prev=n_new;
-
temp->next=n_new;
-
n_new->prev=temp;
-
}
-
//---------------- FUNCTION ADD_END ----------------------------------------
-
void add_end(dll head,dll n_new)
-
{
-
dll temp;
-
temp=head;
-
while(temp->next!=NULL)
-
temp=temp->next;
-
temp->next=n_new;
-
n_new->prev=temp;
-
n_new->next=NULL;
-
}
-
//---------------- FUNCTION DELETE ------------------------------------------
-
int delete(dll head,int data)
-
{
-
dll temp;
-
temp=head;
-
while(temp)
-
{
-
if(temp->val==data)
-
{
-
temp->prev->next=temp->next;
-
temp->next->prev=temp->prev;
-
temp->prev=temp->next->next;
-
return(temp->val);
-
}
-
else
-
temp=temp->next;
-
}
-
-
return(NULL);
-
}
-
//---------------- FUNCTION DISPLAY ----------------------------------------
-
void display(dll head)
-
{
-
dll temp;
-
printf("\n\n\t THE DOUBLY LINKED LIST IS ::");
-
printf("HEAD->");
-
temp=head->next;
-
while(temp)
-
{
-
printf("<-%d->",temp->val);
-
temp=temp->next;
-
}
-
printf("NULL");
-
}
-
//---------------- FUNCTION GET_NODE-----------------------------------------
-
dll get_node()
-
{
-
dll n_new;
-
n_new=malloc(sizeof(struct dlist));
-
printf("\n\n\t ENTER THE VALUE ::");
-
scanf("%d",&n_new->val);
-
n_new->next=NULL;
-
n_new->prev=NULL;
-
return(n_new);
-
}
-
//---------------- FUNCTION CREATE ------------------------------------------
-
dll create()
-
{
-
dll head,n_new,last;
-
char c;
-
head=malloc(sizeof(struct dlist));
-
head->next=NULL;
-
head->prev=NULL;
-
last=head;
-
do
-
{
-
n_new=malloc(sizeof(struct dlist));
-
printf("\n\n\t ENTER THE VALUE ::");
-
scanf("%d",&n_new->val);
-
last->next=n_new;
-
n_new->prev=last;
-
n_new->next=NULL;
-
last=n_new;
-
printf("\n\n\t CREATE ANY MORE NODE (Y/N) ::");
-
c=getche();
-
}while(c=='y'||c=='Y');
-
-
return(head);
-
}
-
//--------------------------------------------------------------------------
-
void main()
-
{
-
dll head,n_new;
-
int choice,data;
-
char c;
-
// textcolor(14);
-
while(1)
-
{
-
//clrscr();
-
printf("\n\n\t THE DOUBLY LINKED LIST OPERATION :: ");
-
printf("\n\n\t 1> CREATE LIST");
-
printf("\n\n\t 2> DISPLAY");
-
printf("\n\n\t 3> ADD AT END");
-
printf("\n\n\t 4> ADD AT BEGINING");
-
printf("\n\n\t 5> SEARCH");
-
printf("\n\n\t 6> DELETE");
-
printf("\n\n\t 7> EXIT");
-
printf("\n\n\t ENTER YOUR CHOICE ::");
-
scanf("%d",&choice);
-
switch(choice)
-
{
-
case 1:head=create();
-
display(head);
-
break;
-
case 2:display(head);
-
break;
-
case 3:new=get_node();
-
add_end(head,n_new);
-
display(head);
-
break;
-
case 4:n_new=get_node();
-
add_beg(head,n_new);
-
display(head);
-
break;
-
case 5:printf("\n\n\t ENTER THE VALUE TO BE SEARCHED :: ");
-
scanf("%d",&data);
-
if(search_val(head,data))
-
{
-
printf("\n\n\t THE VALUE IS PRESENT IN THE LIST ");
-
display(head);
-
}
-
else
-
{
-
printf("\n\n\t THE VALUE IS NOT PRESENT IN THE LIST ");
-
display(head);
-
}
-
break;
-
case 6:printf("\n\n\t ENTER THE VALUE TO BE DELETED ::");
-
scanf("%d",&data);
-
if(search_val(head,data))
-
{
-
data=delete(head,data);
-
printf("\n\n\t THE DATA DELETED FROM THE LIST IS :: %d",data);
-
display(head);
-
}
-
else
-
{
-
if(head->next==NULL)
-
{
-
printf("\n\n\t THE LIST IS EMPTY ");
-
display(head);
-
}
-
else
-
{
-
printf("\n\n\t THE DATA IS NOT PRESENT IN THE LIST ");
-
display(head);
-
}
-
}
-
break;
-
case 7:printf("\n\n\t PRESS ESC TO EXIT ");
-
if(getch()==27)
-
exit(0);
-
break;
-
-
}
-
-
getch();
-
}
-
}
-
//--------------------------------------------------------------------------*/
-
here are the error info. in Dev C
In function `dlist* search_val(dlist*, int)':
19 . invalid conversion from `int' to `dlist*'
19 At global scope:
50 expected unqualified-id before "delete"
......
4 3015 - dll search_val(dll head,int data)
-
{
-
dll temp;
-
temp=head;
-
while(temp)
-
{
-
if(temp->val==data)
-
return(1);
-
else
-
temp=temp->next;
-
}
-
return(0);
-
}
Your function header says this returns a dll, but you only return 0 or 1.
oh , thanks.
one more please :)
after I fix that one , anothers occur :
In function `int n_delete(dlist*, int)':
67 [Warning] converting to non-pointer type `int' from NULL
In function `dlist* get_node()':
87 invalid conversion from `void*' to `dlist*'
In the first case, you are now doing to opposite thing - returning NULL, which only has meaning when used with pointers, when your function promises an int return value.
In the second case, you are using malloc, but not casting the result to anything. malloc returns a void*, and you need a dll*.
Have you tried reading your errors? They provide the line of code where the error/warning occurs, and usually give an accurate description of what's going on. All I've done is look at the line number, go to that spot, and see another simple mistake. You can do the exact same thing without me, I'm sure.
hi Ganon11 !
after reading your suggestion then I 've corrected them
about Null : I just ignore it . :)
// return(NULL);
about malloc
it now is
n_new=(struct dlist*) malloc(sizeof(struct dlist));
that's all I could do.
and then I compiled. It worked :but it run incorrectly with the delete function.( because of the return I ignored ?
definitely I need more reading about C
Thank you for your patience !
Sign in to post your reply or Sign up for a free account.
Similar topics
by: surrealtrauma |
last post by:
I want to ask what's the differences between doubly liked list and linear
liked list, and also the circular doubly liked list in terms of
implementation. THX
|
by: dssuresh6 |
last post by:
Whether browsing forward or backward can be done using a singly linked
list. Is there any specific case where a doubly linked list is needed?
For people who say that singly linked list allows...
|
by: free2cric |
last post by:
Hi,
how to detect head and tail in cyclic doubly link list ?
Thanks,
Cric
|
by: drewy2k12 |
last post by:
Heres the story, I have to create a doubly linked list for
class, and i have no clue on how to do it, i can barely create a
single linked list. It has to have both a head and a tail pointer,
and...
|
by: murali |
last post by:
Hi,
I want to insert a node in an sorted doubly linked list of integers in
ascending order. The list should not have duplicate nodes. I need an
algorithm (assuming an object oriented language)
...
|
by: tonywinslow1986 |
last post by:
I'm reading MIT's book "Introduction to Algorithms".
The following is one of the excercises from it:
<
10.2-8
Explain how to implement doubly linked lists using only one pointer
value np per...
|
by: maruf.syfullah |
last post by:
Consider the following Class definitions:
class AClass
{
int ai1;
int ai2;
public:
CClass* c;
AClass(){}
|
by: adam.kleinbaum |
last post by:
Hi there,
I'm a novice C programmer working with a series of large (30,000 x
30,000) sparse matrices on a Linux system using the GCC compiler. To
represent and store these matrices, I'd like to...
|
by: kalar |
last post by:
Hello.
we have this struct and we must to make a linked list
struct node {
char name;
char phone;
struct node *prevName; // previous node alphabetically
struct node *prevNumber; //...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |