This website uses cookies to ensure you have the best experience.

2395 words - 10 pages

1

List vs Arrays
Two built-in data structures that can be used to organize data, or to create other data structures:

• Lists • Arrays

Lists
A list is an ordered set of data. It is often used to store objects that are to be processed sequentially.

Arrays
An array is an indexed set of variables, such as dancer[1], dancer[2], dancer[3],… It is like a set of boxes that hold things. A list is a set of items. An array is a set of variables that each store an item.

Arrays and Lists
You can see the difference between arrays and lists when you delete items.

Arrays and Lists
In a list, the missing spot is filled in when something is deleted.

Arrays and ...view middle of the document...

For example, the following struct could be used to create a list where each node holds a data:
struct Node { int data; Node *next; };
12

data

Declarations
• The next step is to declare a pointer to serve as the list head, as shown below.

• Once you have declared a node data structure and have created a NULL head pointer, you have an empty linked list. • The next step is to implement operations with the list.
13

Operations in a simple linked list:
• Add or Append a node in the list void appendNode(value); • Insert a node in the list void insertNode(value); • Delete a node from the list void deleteNode(value); • Iterate through the list to display items.

void isplayList(value);

Adding or Appending a Node to the List

• To append a node to a linked list means to add the node to the end of the list. • The pseudocode is shown below. The C++ code follows. Create a new node. Store data in the new node. If there are no nodes in the list Make the new node the first node. Else Traverse the List to Find the last node. Add the new node to the end of the list. End If.
15

Void appendNode(int value)
{
Node *newNode, *curr; // Allocate a new node & store data newNode = new Node; newNode->data = value; newNode->next = NULL; // If there are no nodes in the list // make newNode the first node if (!head) head = newNode; else // Otherwise, insert newNode at end { // Initialize curr to head of list curr = head; // Find the last node in the list while (curr->next) curr = curr->next; // Insert newNode as the last node curr->next = newNode; } }
16

appendNode(int value) appendNode(2.5)

head = new Node;

newNode = new Node; newNode->data = value; newNode->next = NULL;

17

Making first node as head
The next statement to execute is the following if statement. if (!head) head = newNode;

There are no more statements to execute

18

Append another node with the value 7.9. appendNode(7.9)
Once again, the first three statements in the function create a new node, store the argument in the node's data member, and assign its next pointer to NULL.
newNode = new Node; newNode->data = value; newNode->next = NULL;

19

Since head no longer points to NULL, the else part of the if statement executes:
else // Otherwise, insert newNode at end { // Initialize nodePtr to head of list curr = head; // Find the last node in the list while (curr->next) curr = curr->next; // Insert newNode as the last node curr->next = newNode; }

curr

curr

Append another node with the value 12.6. appendNode(12.6)

The third time appendNode is called, 12.6 is passed as the argument. Once again, the first three statements create a node with the argument stored in the value member.
newNode = new Node; newNode->data = value; newNode->next = NULL;

21

Since head no longer points to NULL, the else part of the if statement executes:
else // Otherwise, insert newNode at end { // Initialize nodePtr to head of list...

## Other Essays Like Linkedlist

### Living In A Cashless Society Essay

1637 words - 7 pages Money in a traditional sense no longer exists. Money is becoming much of a concept than a physical material, and most ordinary bitter have not see the reality of the switch. People today are using credit and debit cards on a regular basis and in everyday situations such as meal purchased at fast food, highway tolls, clothing, groceries, gas stations, etc. all of these means of systems could be regarded as a cashless society or world. The question

### The French And Indian War: The "Real" First World War

1955 words - 8 pages The Seven Years War, or more commonly referred to as “The French and Indian War”, has been called the true First World War. In this book The French and Indian War: Deciding the Fate of North America, the author and historian Walter R. Borneman paints a detailed and elaborate picture that justifies the claim of it being the first true war of global proportions. If ever there truly was a climax to the never ending feud of the European powers

### Is The Use Of Animals In Medical Research A Necessary Measure?

1513 words - 7 pages Throughout history, animals have been used in experiments to test product safety and obtain medical knowledge that benefits both humans and animals alike. Every year there are numerous medical breakthroughs, such as medications and surgical instruments, which are tested on animals to insure their safety before they are deemed acceptable for human use. Even though the results of the experiments saved millions of human lives, they are also

### Education And The Evolving Job Market

2363 words - 10 pages The lives of students today are changing. They are preparing for lives and jobs that have never before existed. If teachers hope to have a significant and worthwhile impact on these quickly changing lives, they must change the way they think, prepare, and instruct our future generations. Children cannot afford to have teachers who remain stagnant in their methods and ideals. Students crave instructors that are willing to allow them to tap

### Young And Relentless

1737 words - 7 pages There are numerous influences that can be responsible of teenager’s behaviors and attitude as they develop. One factor that is important to these behaviors is parental figures being over involved or uninvolved in their children’s lives. Many of these effects include illegal substance abuse, rising sexual activity, underage alcohol consumption, and tobacco use. Studies show parental participation plays a key role in the characteristics developed

### The Natural Law Theory

1231 words - 5 pages Obeying by the natural law theory is the only true and moral way to live life; especially a life lived in God’s image. God’s presence is a guiding factor to obtaining a moral and virtuous life, which can only be obtained by following the natural law theory. God created a set of laws as a supreme guide for humans to live life, like any law these laws were created to ensure wellbeing for everyone. The laws he created are the civil law, the natural

### Resolved: Presidential Signing Statements Threaten To Undermine The Rule Of Law And The Separation Of Powers

1811 words - 8 pages The subject of signing statements has created much debate among the houses of Congress, government officials, and the public alike. These signing statements fall under the categories of constitutional and legislative history signing statements. Constitutional signing statements are those in which the president deems certain provisions of the legislation as unconstitutional, therefore they should not be enforced (Bradley & Posner, 2006

### Oppressive Systems Of Government In Egypt And Animal Farm

1529 words - 7 pages As in Egypt, Orwell demonstrates through his allegorical novel “Animal Farm” that leaders are able to establish and maintain power over a people, and in turn create an oppressive and corrupt government system. Orwell shows the significant difference in the education and levels of knowledge in the animals, and how the government takes advantage of this difference. The split between the levels of intelligence is portrayed in the first chapter when

### The Pathway To Psychosis

1415 words - 6 pages “How all occasions do inform against me” is a line from act IIII, scene IIII of William Shakespeare’s Hamlet. This line, spoken by Hamlet, expresses his emotional state as he is currently overwhelmed by the death of his father, the king of Denmark, and the situation surrounding it. After Hamlet learns of his father’s death he finds out that his mother has married Claudius, Hamlet’s uncle. On top of all of that, Hamlet soon after

### Rated “M” For “More Censorship Not Needed”

1241 words - 5 pages Since the moment video games became a commercial success there have been people who have pushed for unfair amounts of censorship to be placed upon the content of the games and its availability to children. These groups push for increased regulations on content but there is already an appointed group to handle this issue, the ESRB. Even though there has been an increase in mature content in the video game industry, increased censorship is not

### Four Components Of A Legally Astute Social Media Marketing Manager

1914 words - 8 pages With the advances in technology constantly changing companies have to find better ways to market their products to consumers. The explosion of Facebook has given companies a way to market products to consumers. Examine how a legally astute manager can use social media to his advantage. Review different forms of dispute resolution and determine which one works the best. What is the best course of action, the government can use to

## Related Papers

### Mca Syllabus Essay

2789 words - 12 pages | | |ListIterator Interface | | |ArrayList, LinkedList Classes | | |List Usage Example

### The Separation Of Capital Ownership And Control

1577 words - 7 pages The argument of whether the separation of capital ownership and control is an efficient form of organization has constantly been a controversial issue. The criticism whether the controllers’ act is in the best interest of the owners’ wills never end as long as hired managers operate management. As the number of public companies has been increasing over the course of this century, meanwhile the American style of contact based corporation has

### The Versatility And Flexibility Of Oled's

1014 words - 5 pages In April 1, 2002, organic light emitting diodes gain rise in the scientific community with their published, more practical form at Ames Laboratory. “Scientists at the U.S. Department of Energy's Ames Laboratory, in collaboration with scientists at the University of Michigan, Ann Arbor, have developed and demonstrated a novel, fluorescence-based chemical sensor that is more compact, versatile and less expensive than existing technology of its

### Comparing The Moral Virtues Of Antony And Julian The Apostate

1103 words - 5 pages Roman emperor Julian the Apostate and Christian leader Antony both exhibited many qualities of character during their existence. Both of them led very distinctive lives although shared several ethical values. Book 25 of “The Later Roman Empire” and the book “Early Christian Lives” show concrete evidence of this. In the following essay, I will argue how both leaders’ lives were devoted to their religious beliefs and their mutual cardinal virtues