我必须创建一个名为Myset的类,其中包含IsEmpty(),Insert(Object O)等方法.我想使用Linked对象列表来实现Myset类.但是,由于我是Java的新手,我不得不创建对象本身,即使我不清楚如何开始.我想到了这样的事情:
public class Myset {
LinkedList<Object> LL = new LinkedList<Object>();
}
Run Code Online (Sandbox Code Playgroud)
我还需要编写一个方法:: public Myset Union(Myset a)返回一个集合,它是当前集合与集合a的并集.这可以通过迭代a来完成,如果a中特定索引处的元素不包含在LL中,那么我们将该元素添加到LL.但是我如何在Java代码中编写它?
PS:这是一个赋值问题,我们不允许使用Sets实现.
我想知道这段代码是否正确删除了第一个节点,还是我必须将列表的头部作为指针传递?
void List::deleteFirst()
{
temp = head;
head = head->next;
delete temp;
}
Run Code Online (Sandbox Code Playgroud)
这是班级 List
class List
{
private:
struct node
{
int data;
node * next;
};
node * head;
node * curr;
node * temp;
public:
//List();
//void AddNode(int addData);
//void DeleteNode(int delData);
void deleteFirst();
//void PrintList();
};
Run Code Online (Sandbox Code Playgroud) 我需要有关 Java 8 中 LinkedList 的 foreach 方法的帮助。我需要从第二个元素开始。我不知道该怎么做。
我编写了一个程序,将给定的十进制数转换为其数字的链表.当我执行下面的程序它挂起但我不知道为什么?
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
struct node *convert_num(int num)
{
struct node *list = NULL;
while(num != 0)
{
list = malloc(sizeof(struct node));
list->data = num % 10;
list->next = convert_num(num/10);
}
return list;
}
int main()
{
struct node *n1;
n1 = convert_num(354);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个程序convert_num()功能齐全.
我有以下代码:
ArrayList<String> words;
words = new ArrayList<String>();
words.add("is");
words.add("us");
ListIterator<String> it;
it = words.listIterator();
it.add("##");
System.out.println(words);
it.next();
it.next();
it.previous();
it.set("##");
System.out.println(words);
Run Code Online (Sandbox Code Playgroud)
我希望输出会是## us ##,但是当我运行程序时它会返回## is ##.我希望这与ListIterator添加项目ArrayList而不是ArrayList向其自己添加项目有关.
为什么程序以这种方式运行?
代码在编译时给了我错误,我不知道为什么这个问题是关于一个政策公司但是这里没有任何关系只是为了让你明白我想要做什么
我认为错误在"(*h)= temp"行中
typedef struct
{
char cmp_name[20];
int pol_code;
float pol_price;
int drivers;
float new_d;
float old_d;
} POL;
typedef struct node
{
POL policy;
struct node *next;
} NODE;
void ins(NODE **h,NODE *p)
{
NODE *temp;
temp=(NODE*)malloc(sizeof(NODE));
if(p==NULL)
{
(*h)=temp;
temp->next=NULL;
}
else
{
p->next=temp;
p=p->next;
temp->next=NULL;
}
printf("\nEnter Company Name: ");
scanf("%s",temp->policy.cmp_name);
printf("\nEnter Policy Code: ");
scanf("%d",temp->policy.pol_code);
printf("\nEnter Policy Price: ");
scanf("%f",temp->policy.pol_price);
printf("\nEnter Number of Drivers: ");
scanf("%d",temp->policy.drivers);
printf("\nAddon for a New Driver: ");
scanf("%f",temp->policy.new_d);
printf("\nAddon for …Run Code Online (Sandbox Code Playgroud) 我在while循环中写了条件但错误
curr unclared(首次使用此功能)
虽然我在插入函数中使用了变量curr.
insert(struct node **start)
{ struct node *temp;
temp=(struct node *)malloc(sizeof(struct node);
temp-> data=75;
temp->next= NULL;
if(*start==NULL)
{*start= temp;}
else
{struct node *curr=*start;}
while(curr->next!=NULL)
{curr= curr->next;
curr-> next= temp;
}
}
Run Code Online (Sandbox Code Playgroud) 我有两个链接列表具有唯一但在洗牌顺序中具有相同的元素.
然后随机元素从list1中删除.如何确定已删除的元素?
例:
list1 0 3 7 8 1
list2 3 7 8 1 0
..deleting ..
list1 - 3 7 8 1
list2 3 7 8 1 0
答案:0
最重要的部分是我需要通过O(N)来完成.
我目前正在使用数据结构和算法类,结果证明它非常适合链接列表的概念.不幸的是,我的教授不是解释代码的最佳人选.我搜索了许多网站,试图了解如何构建一个链表,并能够在主要调用它,但由于某种原因,它只是不坚持.据说我有以下代码,我做错了吗?如何在数据中插入数字以及如何从一个节点移动到另一个节点?如何在main中调用节点类并打印出数据值?请向我解释一下,我是一个5岁的孩子.我正在使用C++代码块.谢谢
#include <iostream>
using namespace std;
class LinkedList
{
class Node
public:
{
Node (int data, Node *n);
int data;
Node *next;
};
Node *head;
};
int main()
{
LinkedList::Node NodeObj;
NodeObj.data = 5;
cout <<NodeObj.data;
return 0;
}
Run Code Online (Sandbox Code Playgroud) linked-list ×9
c ×3
c++ ×3
java ×3
algorithm ×1
big-o ×1
class ×1
foreach ×1
listiterator ×1
nodes ×1
pointers ×1
pseudocode ×1