Solved

function creation ..200 pts urgent !

Posted on 1997-12-04
2
198 Views
Last Modified: 2010-04-02
knowing

struct data { char partno[6];
              float cost;
              int quan;
            };

struct node {struct data dat;
             struct node *link;
            };

i need to create a function
delete_from_ordered_list(struct node **hd, char *part_name);

such that

pre:  hd points to the head pointer for the list.  part_name points to a string (that identifies the node to be deleted)
post:  if a node having a partno equal part_name was on the list, it has been deleted and the function returneed 1.  Otherwise, no node was deleted and the function returned a 0.

 
0
Comment
Question by:thorn120497
2 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1256503
So are you in the same class as ch4?
0
 
LVL 1

Accepted Solution

by:
yl earned 200 total points
ID: 1256504
delete_from_ordered_list(struct node **hd, char *part_name)
{
  struct node *pNode = *hd;
  strcut node *pPrevNode = NULL;
  int iFound = 0;
 
  while (pNode != NULL) {
    if (strcmp(part_name, pNode->dat.part_no) == 0) {
       iFound = 1;
       if (pPrevNode == NULL) {
          *hd = pNode->link;
          delete pNode;
          pNode = *hd;
       }
       else {
          pPrevNode->link = pNode->link;
          delete pNode;
          pNode = pPrevNode->link;
       }
    }
    else {
       pPrevNode = pNode;
       pNode = pNode->link;
    }
  }

  return (iFound);
}
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to align numbers in C using the %d 2 89
Passing command line arguments in C 10 85
C language IDE – Compilers installation 14 67
Why isn't object file created? 6 41
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now